package com.eportal.struts.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletResponse;

import mpi.client.data.OrderData;
import mpi.client.exception.PayException;
import mpi.client.trans.TopPayLink;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import cfca.payment.api.system.PaymentEnvironment;
import cfca.payment.api.system.TxMessenger;
import cfca.payment.api.tx.Tx1312Request;
import cfca.payment.api.tx.Tx1345Request;
import cfca.payment.api.tx.Tx134xResponse;
import cfca.payment.api.vo.BankAccount;
import cfca.util.Base64;

import com.eportal.ORM.CodeView;
import com.eportal.ORM.FeeView;
import com.eportal.ORM.MpayAccount;
import com.eportal.ORM.MpayFee;
import com.eportal.ORM.MpayPayinfo;
import com.eportal.ORM.MpayTradeFee;
import com.eportal.ORM.MpayUser;
import com.eportal.ORM.NetPayJnls;
import com.eportal.ORM.NetPayJnlsId;
import com.eportal.ORM.TLoan;
import com.eportal.ORM.TLoanId;
import com.eportal.ORM.TcardAccountInfo;
import com.eportal.ORM.TcardAccountInfoId;
import com.eportal.ORM.UserView;
import com.eportal.ORM.ViewWtPepPayinfo;
import com.eportal.ORM.WtPepPayAccount;
import com.eportal.ORM.WtPepPayinfo;
import com.eportal.ORM.WtPepPayinfoId;
import com.eportal.ORM.WtCardAccountInfo;
import com.eportal.ORM.WtCardAccountInfoId;
import com.eportal.ORM.WtZfxtInfo;
import com.eportal.ORM.WtZfxtInfoGd;
import com.eportal.ORM.WtZfxtInfoId;
import com.eportal.chinapay.SignData;
import com.eportal.core.BaseAction;
import com.eportal.core.Loan;
import com.eportal.core.Page;
import com.eportal.core.Payinfo;
import com.eportal.core.Util;
import com.eportal.core.WtAccount;
import com.eportal.core.cardAccountInfo;
import com.eportal.gd.Conf;
import com.eportal.gd.TransContent;
import com.eportal.gd.TransferRespondRecord;
import com.eportal.gd.b2e004001;
import com.eportal.gd.transfer;
import com.eportal.gd.transferReq;
import com.eportal.gd.transfer_request;
import com.eportal.service.AdminService;

public class RemitAction extends BaseAction {
	AdminService service;
	AdminService serviceOracle;
	private Page page;
	private String start = "0";
	private String limit = "30";
	private boolean success;
	private String message;
	private String payIdNo;
	private String flag;
	private String update;
	private String alldk;
	private String key;
	
	

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getAlldk() {
		return alldk;
	}

	public void setAlldk(String alldk) {
		this.alldk = alldk;
	}

	private String payOutAccount;

	public String getPayOutAccount() {
		return payOutAccount;
	}

	public void setPayOutAccount(String payOutAccount) {
		this.payOutAccount = payOutAccount;
	}

	private String rcvbankCdno;

	public String getRcvbankCdno() {
		return rcvbankCdno;
	}

	public void setRcvbankCdno(String rcvbankCdno) {
		this.rcvbankCdno = rcvbankCdno;
	}

	public String getUpdate() {
		return update;
	}

	public void setUpdate(String update) {
		this.update = update;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String getPayIdNo() {
		return payIdNo;
	}

	public void setPayIdNo(String payIdNo) {
		this.payIdNo = payIdNo;
	}

	public String getPredk() {
		return predk;
	}

	public void setPredk(String predk) {
		this.predk = predk;
	}

	public String getTypedk() {
		return typedk;
	}

	public void setTypedk(String typedk) {
		this.typedk = typedk;
	}

	private String payid;
	private String startDate;
	private String endDate;

	private String tcard;
	private String termid;

	private String predk;
	private String typedk;

	public String getTcard() {
		return tcard;
	}

	public void setTcard(String tcard) {
		this.tcard = tcard;
	}

	public String getTermid() {
		return termid;
	}

	public void setTermid(String termid) {
		this.termid = termid;
	}

	private String rcvCdno;
	private String rcvName;
	private String rcvBankname;
	private String rcvBankno;
	private String rcvMobile;
	private String rcvTerm;
	private String rcvFlag;
	private String rcvDate;
	private String rcvBankjx;
	private String rcvType;
	private String rcvTermCode;
	private String rcvMerCode;
	private String city;
	private String province;
	private String bankname;

	private String payInBankCode;
	private String payAmt;
	private String payRemark;
	private String payPhone;
	private String payInBankName;
	private String payInBankName2;
	private String payInType;
	private String payMerCode;
	private String payTerCode;
	private String payId;
	private String id;
	private List banklist;
	private List<MpayAccount> paylist;
	private List<Payinfo> infolist;
	private List<MpayUser> ulist;
	private String payInName;
	private String payInAccount;
	private String payFee;
	private String payAllAmt;
	private String payBankType;
	private String mpayUsername;

	private String signature;
	private String action;
	private String msg;

	private String userid;
	private String remark;
	private String mercode;
	private String tercode;
	private String trancde;
	private String feesType;
	private String factor1;
	private String factor2;
	private String factor3;
	private String proportion1;
	private String proportionUp1;
	private String proportion2;
	private String proportion3;
	private String proportionUp2;
	private String proportionUp3;
	private String bank;

	private String acc_bank;
	private String acc_type;
	private String acc_amt;
	private String acc_remark;
	private String mobiles;
	private String content;

	boolean succ = false;

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getBankname() {
		return bankname;
	}

	public void setBankname(String bankname) {
		this.bankname = bankname;
	}

	public String getMobiles() {
		return mobiles;
	}

	public void setMobiles(String mobiles) {
		this.mobiles = mobiles;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;

	}

	public String getMercode() {
		return mercode;
	}

	public void setMercode(String mercode) {
		this.mercode = mercode;
	}

	public String getTercode() {
		return tercode;
	}

	public void setTercode(String tercode) {
		this.tercode = tercode;
	}

	public String getTrancde() {
		return trancde;
	}

	public void setTrancde(String trancde) {
		this.trancde = trancde;
	}

	public boolean getSucc() {
		return succ;
	}

	public void setSucc(boolean succ) {
		this.succ = succ;
	}

	public String getAcc_bank() {
		return acc_bank;
	}

	public void setAcc_bank(String accBank) {
		acc_bank = accBank;
	}

	public String getAcc_type() {
		return acc_type;
	}

	public void setAcc_type(String accType) {
		acc_type = accType;
	}

	public String getAcc_amt() {
		return acc_amt;
	}

	public void setAcc_amt(String accAmt) {
		acc_amt = accAmt;
	}

	public String getAcc_remark() {
		return acc_remark;
	}

	public void setAcc_remark(String accRemark) {
		acc_remark = accRemark;
	}

	public String getBank() {
		return bank;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public List<MpayUser> getUlist() {
		return ulist;
	}

	public void setUlist(List<MpayUser> ulist) {
		this.ulist = ulist;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getFeesType() {
		return feesType;
	}

	public void setFeesType(String feesType) {
		this.feesType = feesType;
	}

	public String getFactor1() {
		return factor1;
	}

	public void setFactor1(String factor1) {
		this.factor1 = factor1;
	}

	public String getFactor2() {
		return factor2;
	}

	public void setFactor2(String factor2) {
		this.factor2 = factor2;
	}

	public String getFactor3() {
		return factor3;
	}

	public void setFactor3(String factor3) {
		this.factor3 = factor3;
	}

	public String getProportion1() {
		return proportion1;
	}

	public void setProportion1(String proportion1) {
		this.proportion1 = proportion1;
	}

	public String getProportionUp1() {
		return proportionUp1;
	}

	public void setProportionUp1(String proportionUp1) {
		this.proportionUp1 = proportionUp1;
	}

	public String getProportion2() {
		return proportion2;
	}

	public void setProportion2(String proportion2) {
		this.proportion2 = proportion2;
	}

	public String getProportion3() {
		return proportion3;
	}

	public void setProportion3(String proportion3) {
		this.proportion3 = proportion3;
	}

	public String getProportionUp2() {
		return proportionUp2;
	}

	public void setProportionUp2(String proportionUp2) {
		this.proportionUp2 = proportionUp2;
	}

	public String getProportionUp3() {
		return proportionUp3;
	}

	public void setProportionUp3(String proportionUp3) {
		this.proportionUp3 = proportionUp3;
	}

	public String getMpayUsername() {
		return mpayUsername;
	}

	public void setMpayUsername(String mpayUsername) {
		this.mpayUsername = mpayUsername;
	}

	public String getPayBankType() {
		return payBankType;
	}

	public void setPayBankType(String payBankType) {
		this.payBankType = payBankType;
	}

	public String getPayInBankName2() {
		return payInBankName2;
	}

	public void setPayInBankName2(String payInBankName2) {
		this.payInBankName2 = payInBankName2;
	}

	public String getPayFee() {
		return payFee;
	}

	public void setPayFee(String payFee) {
		this.payFee = payFee;
	}

	public String getPayAllAmt() {
		return payAllAmt;
	}

	public void setPayAllAmt(String payAllAmt) {
		this.payAllAmt = payAllAmt;
	}

	public List<Payinfo> getInfolist() {
		return infolist;
	}

	public void setInfolist(List<Payinfo> infolist) {
		this.infolist = infolist;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getPayid() {
		return payid;
	}

	public void setPayid(String payid) {
		this.payid = payid;
	}

	// 上传文件集合
	private List<File> file;
	// 上传文件名集合
	private List<String> fileFileName;
	// 上传文件内容类型集合
	private List<String> fileContentType;

	public List<File> getFile() {
		return file;
	}

	public void setFile(List<File> file) {
		this.file = file;
	}

	public List<String> getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(List<String> fileFileName) {
		this.fileFileName = fileFileName;
	}

	public List<String> getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(List<String> fileContentType) {
		this.fileContentType = fileContentType;
	}

	public List<MpayAccount> getPaylist() {
		return paylist;
	}

	public void setPaylist(List<MpayAccount> paylist) {
		this.paylist = paylist;
	}

	public String getPayInBankCode() {
		return payInBankCode;
	}

	public void setPayInBankCode(String payInBankCode) {
		this.payInBankCode = payInBankCode;
	}

	public String getPayAmt() {
		return payAmt;
	}

	public void setPayAmt(String payAmt) {
		this.payAmt = payAmt;
	}

	public String getPayRemark() {
		return payRemark;
	}

	public void setPayRemark(String payRemark) {
		this.payRemark = payRemark;
	}

	public String getPayPhone() {
		return payPhone;
	}

	public void setPayPhone(String payPhone) {
		this.payPhone = payPhone;
	}

	public String getPayInBankName() {
		return payInBankName;
	}

	public void setPayInBankName(String payInBankName) {
		this.payInBankName = payInBankName;
	}

	public String getPayInType() {
		return payInType;
	}

	public void setPayInType(String payInType) {
		this.payInType = payInType;
	}

	public String getPayMerCode() {
		return payMerCode;
	}

	public void setPayMerCode(String payMerCode) {
		this.payMerCode = payMerCode;
	}

	public String getPayTerCode() {
		return payTerCode;
	}

	public void setPayTerCode(String payTerCode) {
		this.payTerCode = payTerCode;
	}

	public String getPayId() {
		return payId;
	}

	public void setPayId(String payId) {
		this.payId = payId;
	}

	public String getPayInName() {
		return payInName;
	}

	public void setPayInName(String payInName) {
		this.payInName = payInName;
	}

	public String getPayInAccount() {
		return payInAccount;
	}

	public void setPayInAccount(String payInAccount) {
		if (payInAccount != null)
			payInAccount = payInAccount.replace(" ", "");
		this.payInAccount = payInAccount.replace("-", "");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public AdminService getServiceOracle() {
		return serviceOracle;
	}

	public void setServiceOracle(AdminService serviceOracle) {
		this.serviceOracle = serviceOracle;
	}

	public String getRcvCdno() {
		return rcvCdno;
	}

	public List<WtZfxtInfoId> getBanklist() {
		return banklist;
	}

	public void setBanklist(List<WtZfxtInfoId> banklist) {
		this.banklist = banklist;
	}

	public void setRcvCdno(String rcvCdno) {
		if (rcvCdno != null)
			rcvCdno = rcvCdno.replace(" ", "").replace("-", "");
		this.rcvCdno = rcvCdno;
	}

	public String getRcvName() {
		return rcvName;
	}

	public void setRcvName(String rcvName) {
		this.rcvName = rcvName;
	}

	public String getRcvBankname() {
		return rcvBankname;
	}

	public void setRcvBankname(String rcvBankname) {
		this.rcvBankname = rcvBankname;
	}

	public String getRcvBankno() {
		return rcvBankno;
	}

	public void setRcvBankno(String rcvBankno) {
		this.rcvBankno = rcvBankno;
	}

	public String getRcvMobile() {
		return rcvMobile;
	}

	public void setRcvMobile(String rcvMobile) {
		this.rcvMobile = rcvMobile;
	}

	public String getRcvTerm() {
		return rcvTerm;
	}

	public void setRcvTerm(String rcvTerm) {
		this.rcvTerm = rcvTerm;
	}

	public String getRcvFlag() {
		return rcvFlag;
	}

	public void setRcvFlag(String rcvFlag) {
		this.rcvFlag = rcvFlag;
	}

	public String getRcvDate() {
		return rcvDate;
	}

	public void setRcvDate(String rcvDate) {
		this.rcvDate = rcvDate;
	}

	public String getRcvBankjx() {
		return rcvBankjx;
	}

	public void setRcvBankjx(String rcvBankjx) {
		this.rcvBankjx = rcvBankjx;
	}

	public String getRcvType() {
		return rcvType;
	}

	public void setRcvType(String rcvType) {
		this.rcvType = rcvType;
	}

	public String getRcvTermCode() {
		return rcvTermCode;
	}

	public void setRcvTermCode(String rcvTermCode) {
		this.rcvTermCode = rcvTermCode;
	}

	public String getRcvMerCode() {
		return rcvMerCode;
	}

	public void setRcvMerCode(String rcvMerCode) {
		this.rcvMerCode = rcvMerCode;
	}

	public AdminService getService() {
		return service;
	}

	public void setService(AdminService service) {
		this.service = service;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getStart() {
		return start;
	}

	public void setStart(String start) {
		this.start = start;
	}

	public String getLimit() {
		return limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String redcardinfo() {
		LOG.info("读取红卡绑定信息...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = "";
		if (m.getIsAll() == 1) {
			sql += " where '1'='1' ";
		} else {
			String ss = (String) getRequest().getSession().getAttribute(
					"termgroup");
			sql += " where trim(concat('C',RCV_TERM)) in (" + ss + ") ";
		}
		rcvbankCdno = rcvbankCdno == null ? "" : rcvbankCdno.trim();
		if (!rcvbankCdno.equals("")) {
			sql += " and RCV_CDNO like '%" + rcvbankCdno + "%' ";
		}
		rcvName = rcvName == null ? "" : rcvName.trim();
		if (!rcvName.equals("")) {
			sql += " and RCV_NAME like '%" + rcvName + "%' ";
		}
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);
		List userList = serviceOracle.query("from WtCardAccountInfo" + sql,
				start, l);
		page = new Page();
		List tmp = new ArrayList();
		for (int i = 0; i < userList.size(); i++) {
			WtAccount w = new WtAccount();
			WtCardAccountInfo wt = (WtCardAccountInfo) userList.get(i);
			w.setRcvBankjx(wt.getRcvBankjx());
			w.setRcvBankname(wt.getRcvBankname());
			w.setRcvBankno(wt.getRcvBankno());
			w.setRcvCdno(wt.getId().getRcvCdno());
			w.setRcvDate(wt.getRcvDate());
			w.setRcvFlag(wt.getRcvFlag());
			w.setRcvMerCode(wt.getRcvMerCode());
			w.setRcvMobile(wt.getRcvMobile());
			w.setRcvName(wt.getRcvName());
			w.setRcvTerm(wt.getId().getRcvTerm());
			w.setRcvTermCode(wt.getRcvTermCode());
			w.setRcvType(wt.getRcvType());
			tmp.add(w);
		}
		page.setRoot(tmp);
		page.setTotalProperty(serviceOracle
				.countQuery("select count(*) from WtCardAccountInfo" + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	public String feeinfo() {
		LOG.info("读取汇款手续费列表...");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = " where 1 = 1 ";
		mpayUsername = mpayUsername == null ? "" : mpayUsername.trim();
		if (!mpayUsername.equals("")) {
			sql += " and mpay_username like '%" + mpayUsername + "%' ";
		}
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);

		List userList = service.query("from FeeView" + sql, start, l);
		page = new Page();
		List tmp = new ArrayList();
		for (int i = 0; i < userList.size(); i++) {
			tmp.add(((FeeView) userList.get(i)).getId());
		}
		page.setRoot(tmp);
		page.setTotalProperty(service.countQuery("select count(*) from FeeView"
				+ sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	public String tradefeeinfo() {
		LOG.info("读取交易手续费列表...");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = " where 1 = 1 ";
		if(key!=null&&!key.equals(""))
		{
			sql += " and concat(mercode,tercode) like '%"+key+"%' ";
		}
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);
		List userList = service.query("from MpayTradeFee "+sql, start, l);
		page = new Page();
		page.setRoot(userList);
		page.setTotalProperty(service
				.countQuery("select count(*) from MpayTradeFee"));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	public String tbinkinfo() {
		LOG.info("读取T+0账户信息...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = " where T_ORGCODE = '" + m.getId() + "' ";
		rcvCdno = rcvCdno == null ? "" : rcvCdno.trim();
		if (!rcvCdno.equals("")) {
			sql += " and T_CARD like '%" + rcvCdno + "%' ";
		}
		rcvName = rcvName == null ? "" : rcvName.trim();
		if (!rcvName.equals("")) {
			sql += " and T_INNAME like '%" + rcvName + "%' ";
		}
		sql += " order by T_DATE desc ";
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);
		List userList = serviceOracle.query("from TcardAccountInfo " + sql,
				start, l);
		page = new Page();
		List tmp = new ArrayList();
		for (int i = 0; i < userList.size(); i++) {
			TcardAccountInfo t = (TcardAccountInfo) userList.get(i);
			cardAccountInfo c = new cardAccountInfo();
			c.setTCard(t.getId().getTCard());
			c.setTDate(t.getTDate());
			c.setTInbank(t.getTInbank());
			c.setTInbankno(t.getTInbankno());
			c.setTIncard(t.getTIncard());
			c.setTInname(t.getTInname());
			c.setTIntype(t.getTIntype());
			c.setTMercode(t.getTMercode());
			c.setTOrgcode(t.getTOrgcode());
			c.setTPercent(t.getTPercent());
			c.setTPhone(t.getTPhone());
			c.setTRemark(t.getTRemark());
			c.setTTercode(t.getTTercode());
			c.setTTermid(t.getId().getTTermid());
			c.setTType(t.getTType());
			tmp.add(c);
		}
		page.setRoot(tmp);
		page.setTotalProperty(serviceOracle
				.countQuery("select count(*) from TcardAccountInfo " + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;

	}

	public String getRemitlinkinfo() {
		LOG.info("读取汇款人联系本数据...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = " where rcv_term = '" + m.getId() + "' ";
		rcvCdno = rcvCdno == null ? "" : rcvCdno.trim();
		if (!rcvCdno.equals("")) {
			sql += " and rcv_Cdno like '%" + rcvCdno + "%' ";
		}
		rcvName = rcvName == null ? "" : rcvName.trim();
		if (!rcvName.equals("")) {
			sql += " and rcv_Name like '%" + rcvName + "%' ";
		}
		if (rcvFlag != null && rcvFlag.equals("1")) {
			sql += " and rcv_flag = '1' ";
		} else {
			sql += " and rcv_flag = '0' ";
		}
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);
		List userList = service.query("from MpayAccount" + sql, start, l);
		page = new Page();
		page.setRoot(userList);
		page.setTotalProperty(service
				.countQuery("select count(*) from MpayAccount" + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	public String getRemit() {
		LOG.info("读取汇款清单...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = " where PAY_ID = '" + m.getId() + "' ";
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		// System.out.println(sql);
		List userList = service.query("from MpayPayinfo" + sql);
		page = new Page();
		page.setRoot(userList);
		page.setTotalProperty(service
				.countQuery("select count(*) from MpayPayinfo" + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;

	}

//	public String sendSMS() {
//		try {
//			Util.sendSMSToServer(content, mobiles,"1");
//			message = "发送成功！";
//			success = true;
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			message = "发送失败，请稍后再试！";
//			success = false;
//		}
//
//		return SUCCESS;
//	}

	/**
	 * public String getViewPayinfo() { LOG.info("读取VIEW汇款结果数据..."); UserView m
	 * = (UserView) getRequest().getSession().getAttribute( "mpay_user"); int s
	 * = Integer.valueOf(start); int l = Integer.valueOf(limit); String sql =
	 * ""; if (m.getIsAll() == 1) { sql += " where '1'='1' "; } else { sql +=
	 * " where pay_zf_id in (select payZfId from WtPepPayinfo  where PAY_ID = '"
	 * + m.getId() + "')"; } startDate = startDate == null ? "" :
	 * startDate.trim(); endDate = endDate == null ? "" : endDate.trim(); if
	 * (!startDate.equals("") && !endDate.equals("")) { sql +=
	 * " and pay_date between '" + startDate + "' and  '" + endDate + "' "; } id
	 * = id == null ? "" : id.trim(); if (!id.equals("")) { sql +=
	 * " and pay_zf_id like '%" + id + "%'"; } int start = 1; if (s != 0) start
	 * = s / 30 + 1; // System.out.println(sql); sql +=
	 * " order by substr(pay_zf_id,5) desc "; System.out.println(sql); List
	 * userList = serviceOracle.query("from ViewWtPepPayinfo" + sql, start, l);
	 * Hashtable table = new Hashtable(); List pep = serviceOracle
	 * .query("from WtPepPayinfo where pay_zf_id is not null "); for (int i = 0;
	 * i < pep.size(); i++) { WtPepPayinfo w = (WtPepPayinfo) pep.get(i); if
	 * (table.get(w.getPayZfId()) == null) table.put(w.getPayZfId(),
	 * w.getPayQs()); else { String str = (String) table.get(w.getPayZfId()); if
	 * (w.getPayQs().equals("0") || w.getPayQs().equals("1")) { str = str +
	 * w.getPayQs(); table.put(w.getPayZfId(), str); } } }
	 * 
	 * List tmp = new ArrayList(); for (int i = 0; i < userList.size(); i++) {
	 * ViewWtPepPayinfo w = (ViewWtPepPayinfo) userList.get(i); String str =
	 * (String) table.get(w.getPayZfId()); w.setRemark(str == null ? "" : str);
	 * tmp.add(w); } page = new Page(); page.setRoot(tmp);
	 * page.setTotalProperty(serviceOracle
	 * .countQuery("select count(*) from ViewWtPepPayinfo" + sql));
	 * page.setStart(++s); page.setLimit(l = l == 0 ? 30 : l); return SUCCESS; }
	 **/
	public String updateJk() {
		LOG.info("手动汇出借款...");
		Connection c = serviceOracle.getConnection();
		new Conf(Util.ROOTPATH + "/webPay/");
		String in = "";
		String out = "";
		try {
			String sql = "";
			if (update != null) {
				List tmp = serviceOracle
						.query(" from  TLoan where t_incard = '"
								+ payInAccount
								+ "' and t_money/100 = '"
								+ payIdNo
								+ "' and to_char(t_cr_date,'yyyy-MM-dd HH24:mi:ss')  = '"
								+ payInName + "'");
				if (tmp.size() == 0) {
					message = "更新失败，请重试!";
					success = false;
					return SUCCESS;
				} else {
					TLoan tloan = (TLoan) tmp.get(0);
					transferReq t = new transferReq();
					t.setAccountNo("36550188000041547");
					t.setAmount(Util.moveLeftTwo(tloan.getTMoney()));
					t.setNote("借款");
					t.setBankNo(tloan.getTInbankno());
					t.setToAccountName(tloan.getTInname());
					t.setToAccountNo(tloan.getTIncard());
					t.setToBank(tloan.getTInbank());
					if (tloan.getTInbank().indexOf("光大银行") != -1) {
						t.setTransferType("2122");
					} else {
						t.setTransferType("2120");
					}
					if (tloan.getTIntype().equals("2"))
						t.setPerOrEnt("0");
					else
						t.setPerOrEnt("1");
					b2e004001 b = new b2e004001(Util.getBatchID(), t);
					try {
						TransContent tc = b.unPack(Util.sendToGD(b2e004001.url,
								b.toString()));
						sql = "update t_loan t set t.t_respcode = '"
								+ tc.getReturnCode()
								+ "',t.t_respinfo = '"
								+ tc.getReturnMsg()
								+ "',t.t_trace = '"
								+ b.getBatchID()
								+ "' where t.t_incard = '"
								+ payInAccount
								+ "' and t.t_money/100 = '"
								+ payIdNo
								+ "' and to_char(t_cr_date,'yyyy-MM-dd HH24:mi:ss')  = '"
								+ payInName + "'";
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						sql = "update t_loan t set t.t_respcode = 'SSSS',t.t_respinfo = '已发送' where t.t_incard = '"
								+ payInAccount
								+ "' and t.t_money/100 = '"
								+ payIdNo
								+ "' and to_char(t_cr_date,'yyyy-MM-dd HH24:mi:ss')  = '"
								+ payInName + "'";
					}
				}
			} else {
				sql = "update t_loan t set t.t_respcode = '0000',t.t_respinfo = '已汇出',t.t_trace = '"
						+ trancde
						+ "' where t.t_incard = '"
						+ payInAccount
						+ "' and t.t_money/100 = '"
						+ payIdNo
						+ "' and to_char(t_cr_date,'yyyy-MM-dd HH24:mi:ss')  = '"
						+ payInName + "'";
			}

			System.out.println(sql);
			PreparedStatement ps = c.prepareStatement(sql);
			int i = ps.executeUpdate();
			if (i == 0) {
				message = "更新失败，请重试!";
				success = false;
			} else {
				message = "更新成功!";
				success = true;
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "更新失败，请重试!";
			success = false;
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return SUCCESS;
	}

	public String payaccount() {
		LOG.info("读取账户列表...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		if (bank == null)
			bank = "";
		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = "";
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		sql += " where 1=1 ";
		if (!bank.equals("") && !bank.equals("全部")) {
			sql += " and acc_bank like '%" + bank + "%' ";
		}
		if (rcvFlag != null && rcvFlag.equals("1")) {
			sql += " and rcv_flag = '1' ";
		} else {
			sql += " and rcv_flag = '0' ";
		}
		// System.out.println(sql);
		Connection c = serviceOracle.getConnection();
		String in = "";
		String out = "";
		try {
			PreparedStatement ps = c
					.prepareStatement("select sum(ACC_IN_AMT)/100 from Wt_Pep_Pay_Account "
							+ sql + " and acc_in_amt !='-' ");
			ResultSet rset = ps.executeQuery();
			rset.next();
			in = rset.getString(1);
			ps = c
					.prepareStatement("select sum(ACC_OUT_AMT)/100 from Wt_Pep_Pay_Account "
							+ sql + " and acc_out_amt !='-' ");
			rset = ps.executeQuery();
			rset.next();
			out = rset.getString(1);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		sql += " order by acc_date desc";
		List userList = serviceOracle.query("from WtPepPayAccount" + sql,
				start, l);
		WtPepPayAccount w = new WtPepPayAccount();
		DateFormat DF_TO_STRING = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = DF_TO_STRING.parse("1983-03-16 00:00:00");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		w.setAccDate(new Timestamp(date.getTime()));
		w.setAccInAmt("&" + in);
		w.setAccOutAmt("&" + out);
		userList.add(w);
		page = new Page();
		page.setRoot(userList);
		page.setTotalProperty(serviceOracle
				.countQuery("select count(*) from WtPepPayAccount" + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	public String add_payacc() {
		LOG.info("保存汇款余额数据--...");
		System.out.println(acc_amt);
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int amt = 0;
		List list = serviceOracle
				.query(" from WtPepPayAccount where acc_bank = '" + acc_bank
						+ "' order by acc_date desc");
		if (list.size() != 0) {
			amt = Integer.valueOf(((WtPepPayAccount) list.get(0)).getAccAmt());
		}
		WtPepPayAccount w = new WtPepPayAccount();
		try {
			acc_amt = Util.moveRightTwo(acc_amt);
			if (acc_type.equals("贷记")) {
				amt = amt - Integer.valueOf(acc_amt);
				w.setAccOutAmt(acc_amt);
				w.setAccInAmt("-");
			} else {
				amt = amt + Integer.valueOf(acc_amt);
				w.setAccInAmt(acc_amt);
				w.setAccOutAmt("-");
			}
			acc_remark = acc_remark == null || acc_remark.equals("") ? acc_type
					: acc_remark;
			w.setAccAmt(amt + "");
			w.setAccBank(acc_bank);
			w.setAccUser(m.getMpayUserid());
			w.setAccDate(new Timestamp(new Date().getTime()));
			w.setAccRemark(acc_remark);
			serviceOracle.save(w);
			message = "添加信息成功！";
			success = true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "添加信息错误！";
			success = false;
		}
		return SUCCESS;
	}

	public InputStream getExcelremit() {
		LOG.info("下载汇款明细数据...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		String sql = "";
		Hashtable tableT = new Hashtable();
		List tradeT = service.listAll("CodeView");
		for (int i = 0; i < tradeT.size(); i++) {
			CodeView mc = (CodeView) tradeT.get(i);
			tableT.put(mc.getId().getCodeid(), "[" + mc.getId().getBankName()
					+ "] " + mc.getId().getCodename());
		}
		if (m.getIsAll() == 1 || m.getMpayUserid().equals("yanshi")) {
			sql += " where '1'='1' ";
		} else {
			String ss = (String) getRequest().getSession().getAttribute(
					"termgroup");
			sql += " where ( concat('C',PAY_ZF_CARD) in (" + ss
					+ ") or PAY_ZF_TERMID in (" + ss + ") or PAY_ZF_TERMID = '"
					+ m.getMpayUserid() + "' )";
		}
		startDate = startDate == null ? "" : startDate.trim();
		endDate = endDate == null ? "" : endDate.trim();
		if (!startDate.equals("") && !endDate.equals("")) {
			sql += " and (substr(PAY_DATE,0,8) between '" + startDate + "' and '"
					+ endDate + "') ";
		} else {
			sql += " and PAY_DATE like '" + Util.getCurrentDate("yyyyMMdd")
					+ "%' ";
		}
		payInName = payInName == null ? "" : payInName.trim();
		if (!payInName.equals("")) {
			try {
				payInName = new String(payInName.getBytes("ISO-8859-1"),
						"UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			sql += " and PAY_IN_NAME like '%" + payInName + "%' ";
		}
		payInAccount = payInAccount == null ? "" : payInAccount.trim();
		if (!payInAccount.equals("")) {
			sql += " and PAY_IN_ACCOUNT like '%" + payInAccount + "%' ";
		}
		payid = payid == null ? "" : payid.trim();
		if (!payid.equals("")) {
			sql += " and PAY_IN_TRACE = '" + payid + "' ";
		}
		String sqlsum = "select sum(pay_amt)/100 from Wt_Pep_Payinfo" + sql
				+ " and PAY_OUT_STATE = '0000' ";

		String sqlcount = "select count(*) from Wt_Pep_Payinfo" + sql
				+ " and PAY_OUT_STATE = '0000' ";
		Connection c = serviceOracle.getConnection();
		String sum = "0";
		String count = "0";
		try {
			PreparedStatement ps = c.prepareStatement(sqlsum);
			ResultSet rset = ps.executeQuery();
			rset.next();
			sum = rset.getString(1);
			ps = c.prepareStatement(sqlcount);
			rset = ps.executeQuery();
			rset.next();
			count = rset.getString(1);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (succ) {
			sql += " and PAY_OUT_STATE = '0000' ";
		}
		// System.out.println(sql);
		sql += " order by pay_date desc ";
		System.out.println(sql);
		List userList = serviceOracle.query("from WtPepPayinfo" + sql);
		infolist = new ArrayList<Payinfo>();
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet("new sheet");
		HSSFRow row = sheet.createRow((short) 0);
		HSSFCell cell = row.createCell((short) 0);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("建立时间");
		cell = row.createCell((short) 1);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("收款账号");
		cell = row.createCell((short) 2);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("收款银行");
		cell = row.createCell((short) 3);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("收款人姓名");
		cell = row.createCell((short) 4);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("汇款金额");
		cell = row.createCell((short) 5);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("手续费");
		cell = row.createCell((short) 6);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("交易类型");
		cell = row.createCell((short) 7);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("流水号");
		cell = row.createCell((short) 8);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("应答码");
		cell = row.createCell((short) 9);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("汇款日期");
		cell = row.createCell((short) 10);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("状态");
		cell = row.createCell((short) 11);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("支付时间");
		cell = row.createCell((short) 12);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("支付卡号");
		cell = row.createCell((short) 13);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("发送时间");
		cell = row.createCell((short) 14);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("备注");
		Iterator itr = userList.iterator();
		short rowNum = 1;
		WtPepPayinfo w;
		while (itr.hasNext()) {
			row = sheet.createRow(rowNum);
			w = (WtPepPayinfo) itr.next();
			Payinfo p = new Payinfo();
			p.setPayZfCard(Util.toInCard(w.getPayZfCard()));
			p.setPayAmt(Util.FormatSum(w.getPayAmt()));
			p.setPayFee(Util.FormatSum(w.getPayFee()));
			p.setPayAprespn(w.getPayOutBankCode() + "["
					+ w.getPayOutBankCodeInfo() + "]");
			p.setPayId(w.getPayZfTermid());
			p.setPayZfId(w.getId().getPayInTrace());
			p.setPayInAccount(Util.toInCard(w.getId().getPayInAccount()));
			p.setPayInBankCode(w.getPayInBankno());
			p.setPayInBankName(w.getPayInBank());
			p.setSum(sum);
			p.setCount(count);
			p.setPayInName(w.getPayInName().trim());
			p.setPayInType(w.getPayInType());
			p.setPayMerCode(w.getPayZfMercde());
			p.setPayOutAccount(w.getPayOutAccount());
			p.setPayOutBankName(w.getPayOutBank());
			p.setPayOutXy(w.getPayRemark());
			p.setPayPhone("");
			p.setPayQs(w.getPayOutStateInfo());
			p.setPayQsDate("");
			p.setPayRemark((String) tableT.get(w.getPayCode()));
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			p.setPaySendDate(format.format(w.getPayOutDate()));
			p.setPayTerCode(w.getPayZfTermcde());
			String d = w.getId().getPayDate();
			p.setPayTime(d.substring(0, 4) + "-" + d.substring(4, 6) + "-"
					+ d.substring(6, 8) + " " + d.substring(8, 10) + ":"
					+ d.substring(10, 12) + ":" + d.substring(12, 14));
			p.setPayTrace(w.getPayZfTrace());
			String date = "";
			if (w.getPayZfDate() == null)
				p.setPayZfDate("-");
			else {
				date = w.getPayZfDate();
				p.setPayZfDate(date.substring(0, 4) + "-"
						+ date.substring(4, 6) + "-" + date.substring(6, 8));
			}
			p.setPayZfId(w.getPayZfTermid());
			cell = row.createCell((short) 0);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayTime());
			cell = row.createCell((short) 1);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayInAccount());
			cell = row.createCell((short) 2);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayInBankName());
			cell = row.createCell((short) 3);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayInName());
			cell = row.createCell((short) 4);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayAmt());
			cell = row.createCell((short) 5);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayFee());
			cell = row.createCell((short) 6);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayRemark());
			cell = row.createCell((short) 7);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayTrace());
			cell = row.createCell((short) 8);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayAprespn());
			cell = row.createCell((short) 9);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayQsDate());
			cell = row.createCell((short) 10);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(checkQS(p.getPayQs()));
			cell = row.createCell((short) 11);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayZfDate());
			cell = row.createCell((short) 12);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayZfCard());
			cell = row.createCell((short) 13);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPaySendDate());
			cell = row.createCell((short) 14);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(p.getPayOutXy());
			rowNum++;
		}
		row = sheet.createRow(rowNum);
		cell = row.createCell((short) 0);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("成功交易额:");
		cell = row.createCell((short) 1);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue(sum);
		rowNum++;
		row = sheet.createRow(rowNum);
		cell = row.createCell((short) 0);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("成功交易笔数:");
		cell = row.createCell((short) 1);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue(count);
		try {
			OutputStream out = this.getResponse().getOutputStream();
			this.getResponse().setHeader("Content-disposition",
					"attachment; filename=remit.xls");
			this.getResponse().setContentType(
					"application/msexcel;charset=UTF-8");
			wb.write(out);
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public String jkmxinfo() {
		LOG.info("读取T+0借款明细数据...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");

		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		String sql = "";
		if (flag != null && !flag.equals("")) {
			if (flag.equals("1")) {
				sql = " where  T_RESPCODE = 'FFFF' ";
			}
		} else {
			sql = " where 1 = 1 ";
		}
		if (m.getIsAll() == 0) {
			String ss = (String) getRequest().getSession().getAttribute(
					"termgroup");
			sql += " and T_TERMID in (" + ss + ") ";
		}
		int start = 1;
		startDate = startDate == null ? "" : startDate.trim();
		endDate = endDate == null ? "" : endDate.trim();
		if (!startDate.equals("") && !endDate.equals("")) {
			sql += " and (T_DATE between '" + startDate + "' and '" + endDate
					+ "') ";
		} else {
			// sql += " and pay_date = '" + Util.getCurrentDate("yyyyMMdd") +
			// "' ";
		}
		String sqlsum = "select sum(T_MONEY)/100 from T_LOAN" + sql + "";

		String sqlcount = "select count(*) from T_LOAN" + sql + " ";
		Connection c = serviceOracle.getConnection();
		String sum = "0";
		String count = "0";
		try {
			PreparedStatement ps = c.prepareStatement(sqlsum);
			ResultSet rset = ps.executeQuery();
			rset.next();
			sum = rset.getString(1);
			ps = c.prepareStatement(sqlcount);
			rset = ps.executeQuery();
			rset.next();
			count = rset.getString(1);
			c.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		// System.out.println(sql);
		sql += " order by T_CR_DATE desc ";
		System.out.println(sql);

		List userList = serviceOracle.query("from TLoan" + sql, start, l);
		List tmp = new ArrayList<TLoan>();
		for (int i = 0; i < userList.size(); i++) {
			Loan loan = new Loan();
			TLoan w = (TLoan) userList.get(i);
			loan.setTInbank(w.getTInbank());
			loan.setTDate(w.getTDate());
			loan.setTInbankno(w.getTInbankno());
			loan.setTIncard(w.getTIncard());
			loan.setTInname(w.getTInname());
			loan.setTIntype(w.getTIntype());
			loan.setTMoney(w.getTMoney());
			loan.setTRespcode(w.getTRespcode());
			loan.setTRespinfo(w.getTRespinfo());
			loan.setTTrace(w.getTTrace());
			loan.setSum(sum);
			loan.setTCrDate(w.getId().getTCrDate());
			loan.setTCard(w.getId().getTCard());
			loan.setTTermid(w.getId().getTTermid());
			tmp.add(loan);
		}
		page = new Page();
		page.setRoot(tmp);
		page.setTotalProperty(Integer.valueOf(count));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;

	}

	public InputStream excelToJk() {
		LOG.info("下载借款明细数据...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		String sql = " where 1 = 1 ";
		int start = 1;
		startDate = startDate == null ? "" : startDate.trim();
		endDate = endDate == null ? "" : endDate.trim();
		if (!startDate.equals("") && !endDate.equals("")) {
			sql += " and (T_DATE between '" + startDate + "' and '" + endDate
					+ "') ";
		} else {
			// sql += " and pay_date = '" + Util.getCurrentDate("yyyyMMdd") +
			// "' ";
		}

		String sqlsum = "select sum(T_MONEY)/100 from T_LOAN" + sql + "";

		String sqlcount = "select count(*) from T_LOAN" + sql + " ";
		Connection c = serviceOracle.getConnection();
		String sum = "0";
		String count = "0";
		try {
			PreparedStatement ps = c.prepareStatement(sqlsum);
			ResultSet rset = ps.executeQuery();
			rset.next();
			sum = rset.getString(1);
			ps = c.prepareStatement(sqlcount);
			rset = ps.executeQuery();
			rset.next();
			count = rset.getString(1);
			c.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		// System.out.println(sql);
		sql += " order by T_CR_DATE desc ";
		System.out.println(sql);

		List userList = serviceOracle.query("from TLoan" + sql);
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet("new sheet");
		HSSFRow row = sheet.createRow((short) 0);
		HSSFCell cell = row.createCell((short) 0);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("借款卡卡号");
		cell = row.createCell((short) 1);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("绑定终端号码");
		cell = row.createCell((short) 2);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("借款金额");
		cell = row.createCell((short) 3);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("转入卡的户名");
		cell = row.createCell((short) 4);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("转入卡的开户行");
		cell = row.createCell((short) 5);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("开户行行号");
		cell = row.createCell((short) 6);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("转入卡号或账号");
		cell = row.createCell((short) 7);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("账户类型");
		cell = row.createCell((short) 8);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("时间");
		cell = row.createCell((short) 9);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("状态");
		cell = row.createCell((short) 10);
		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue("流水号");
		Iterator itr = userList.iterator();
		short rowNum = 1;
		TLoan wid;
		while (itr.hasNext()) {
			row = sheet.createRow(rowNum);
			wid = (TLoan) itr.next();
			wid.setTCrDate(wid.getId().getTCrDate());
			wid.setTCard(wid.getId().getTCard());
			wid.setTTermid(wid.getId().getTTermid());
			cell = row.createCell((short) 0);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTCard());
			cell = row.createCell((short) 1);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTTermid());
			cell = row.createCell((short) 2);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(Util.FormatSum(wid.getTMoney()));
			cell = row.createCell((short) 3);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTInname());
			cell = row.createCell((short) 4);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTInbank());
			cell = row.createCell((short) 5);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTInbankno());
			cell = row.createCell((short) 6);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTIncard());
			cell = row.createCell((short) 7);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			String type = wid.getTIntype();
			if (type.equals("1"))
				cell.setCellValue("活期储蓄存折");
			else if (type.equals("2"))
				cell.setCellValue("对公帐户");
			else if (type.equals("3"))
				cell.setCellValue("借记卡");
			else if (type.equals("4"))
				cell.setCellValue("信用卡");
			else if (type.equals("5"))
				cell.setCellValue("活期存款账户");
			else
				cell.setCellValue("未知");
			cell = row.createCell((short) 8);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(sf.format(wid.getTCrDate()));
			cell = row.createCell((short) 9);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTRespinfo());
			if (wid.getTRespinfo() == null || wid.equals(""))
				cell.setCellValue("待处理");
			cell = row.createCell((short) 10);
			cell.setEncoding(HSSFCell.ENCODING_UTF_16);
			cell.setCellValue(wid.getTTrace());
			rowNum++;
		}
		try {
			OutputStream out = this.getResponse().getOutputStream();
			this.getResponse().setHeader("Content-disposition",
					"attachment; filename=data.xls");
			this.getResponse().setContentType(
					"application/msexcel;charset=UTF-8");
			wb.write(out);
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public String getRemitdetail() {
		LOG.info("读取汇款明细数据...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");

		int s = Integer.valueOf(start);
		int l = Integer.valueOf(limit);
		Hashtable tableT = new Hashtable();
		List tradeT = service.listAll("CodeView");
		for (int i = 0; i < tradeT.size(); i++) {
			CodeView mc = (CodeView) tradeT.get(i);
			tableT.put(mc.getId().getCodeid(), "[" + mc.getId().getBankName()
					+ "] " + mc.getId().getCodename());
		}
		String sql = "";
		int start = 1;
		if (s != 0)
			start = s / 30 + 1;
		if (m.getIsAll() == 1 || m.getMpayUserid().equals("yanshi")) {
			sql += " where '1'='1' ";
		} else {
			String ss = (String) getRequest().getSession().getAttribute(
					"termgroup");
			sql += " where ( concat('C',PAY_ZF_CARD) in (" + ss
					+ ") or PAY_ZF_TERMID in (" + ss + ") or PAY_ZF_TERMID = '"
					+ m.getMpayUserid() + "' )";
		}
		startDate = startDate == null ? "" : startDate.trim();
		endDate = endDate == null ? "" : endDate.trim();
		if (!startDate.equals("") && !endDate.equals("")) {
			sql += " and (substr(pay_date0,8) between '" + startDate + "' and '"
					+ endDate + "') ";
		} else {
			// sql += " and pay_date = '" + Util.getCurrentDate("yyyyMMdd") +
			// "' ";
		}
		payInName = payInName == null ? "" : payInName.trim();
		if (!payInName.equals("")) {
			sql += " and PAY_IN_NAME like '%" + payInName + "%' ";
		}
		payInAccount = payInAccount == null ? "" : payInAccount.trim();
		if (!payInAccount.equals("")) {
			sql += " and PAY_IN_ACCOUNT like '%" + payInAccount + "%' ";
		}
		payid = payid == null ? "" : payid.trim();
		if (!payid.equals("")) {
			sql += " and PAY_IN_TRACE = '" + payid + "' ";
		}
		String sqlsum = "select sum(pay_amt)/100 from Wt_Pep_Payinfo" + sql
				+ " and PAY_OUT_STATE = '0000' ";

		String sqlcount = "select count(*) from Wt_Pep_Payinfo" + sql
				+ " and PAY_OUT_STATE = '0000' ";
		Connection c = serviceOracle.getConnection();
		String sum = "0";
		String count = "0";
		try {
			PreparedStatement ps = c.prepareStatement(sqlsum);
			ResultSet rset = ps.executeQuery();
			rset.next();
			sum = rset.getString(1);
			ps = c.prepareStatement(sqlcount);
			rset = ps.executeQuery();
			rset.next();
			count = rset.getString(1);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (succ) {
			sql += " and PAY_OUT_STATE = '0000' ";
		}
		// System.out.println(sql);
		sql += " order by pay_date desc";
		System.out.println(sql);
		List userList = serviceOracle
				.query("from WtPepPayinfo" + sql, start, l);
		infolist = new ArrayList<Payinfo>();
		for (int i = 0; i < userList.size(); i++) {
			WtPepPayinfo w = (WtPepPayinfo) userList.get(i);
			Payinfo p = new Payinfo();
			p.setPayAmt(Util.FormatSum(w.getPayAmt()));
			p.setPayFee(Util.FormatSum(w.getPayFee()));
			p.setPayAprespn(w.getPayOutBankCode() + "["
					+ w.getPayOutBankCodeInfo() + "]");
			p.setPayId(w.getPayZfTermid());
			p.setPayInAccount(Util.toInCard(w.getId().getPayInAccount()));
			p.setPayInBankCode(w.getPayInBankno());
			p.setPayInBankName(w.getPayInBank());
			p.setPayZfCard(Util.toInCard(w.getPayZfCard()));
			p.setSum(sum);
			p.setCount(count);
			p.setPayInName(w.getPayInName().trim());
			p.setPayInType(w.getPayInType());
			p.setPayMerCode(w.getPayZfMercde());
			p.setPayOutAccount(w.getPayOutAccount());
			p.setPayOutBankName(w.getPayOutBank());
			p.setPayOutXy(w.getPayRemark());
			p.setPayPhone(w.getPayPhone());
			p.setPayQs(w.getPayOutStateInfo());
			p.setPayQsDate("");
			p.setPayRemark((String) tableT.get(w.getPayCode()));
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			p.setPaySendDate(format.format(w.getPayOutDate()));
			p.setPayTerCode(w.getPayZfTermcde());
			String d = w.getId().getPayDate();
			p.setPayTime(d.substring(0, 4) + "-" + d.substring(4, 6) + "-"
					+ d.substring(6, 8) + " " + d.substring(8, 10) + ":"
					+ d.substring(10, 12) + ":" + d.substring(12, 14));
			p.setPayTrace(w.getPayZfTrace());
			String date = "";
			if (w.getPayZfDate() == null)
				p.setPayZfDate("-");
			else {
				date = w.getPayZfDate();
				p.setPayZfDate(date.substring(0, 4) + "-"
						+ date.substring(4, 6) + "-" + date.substring(6, 8));
			}
			p.setPayZfId(w.getId().getPayInTrace());
			infolist.add(p);
		}
		page = new Page();
		page.setRoot(infolist);
		page.setTotalProperty(serviceOracle
				.countQuery("select count(*) from WtPepPayinfo" + sql));
		page.setStart(++s);
		page.setLimit(l = l == 0 ? 30 : l);
		return SUCCESS;
	}

	// public String getRemitinfo() {
	// LOG.info("读取汇款结果数据...");
	// UserView m = (UserView) getRequest().getSession().getAttribute(
	// "mpay_user");
	// String sql = "";
	// sql += " where '1'='1' ";
	// payInName = payInName == null ? "" : payInName.trim();
	// if (!payInName.equals("")) {
	// sql += " and PAY_IN_NAME like '%" + payInName + "%' ";
	// }
	// payInAccount = payInAccount == null ? "" : payInAccount.trim();
	// if (!payInAccount.equals("")) {
	// sql += " and PAY_IN_ACCOUNT like '%" + payInAccount + "%' ";
	// }
	// payid = payid == null ? "" : payid.trim();
	// if (!payid.equals("")) {
	// sql += " and PAY_IN_TRACE = '" + payid + "' ";
	// }
	// // System.out.println(sql);
	// sql += " order by pay_date desc,pay_time desc ";
	// System.out.println(sql);
	// List userList = serviceOracle.query("from WtPepPayinfo" + sql);
	// infolist = new ArrayList<Payinfo>();
	// for (int i = 0; i < userList.size(); i++) {
	// WtPepPayinfo w = (WtPepPayinfo) userList.get(i);
	// Payinfo p = new Payinfo();
	// p.setPayAmt(Util.FormatSum(w.getPayAmt()));
	// p.setPayFee(Util.FormatSum(w.getPayZfFee()));
	// if (Util.CODELIST.get(w.getPayAprespn()) == null) {
	// p.setPayAprespn(w.getPayAprespn());
	// } else {
	// p.setPayAprespn(w.getPayAprespn() + "["
	// + Util.CODELIST.get(w.getPayAprespn()) + "]");
	// }
	// p.setPayId(w.getPayId());
	// p.setPayInAccount(w.getPayInAccount().trim());
	// p.setPayInBankCode(w.getPayInBankCode());
	// p.setPayInBankName(w.getPayInBankName());
	// p.setPayInName(w.getPayInName().trim());
	// p.setPayInType(w.getPayInType());
	// p.setPayMerCode(w.getPayMerCode());
	// p.setPayOutAccount(w.getPayOutAccount());
	// p.setPayOutBankName(w.getPayOutBankName());
	// p.setPayOutXy(w.getPayOutXy());
	// p.setPayPhone(w.getPayPhone());
	// p.setPayQs(w.getPayQs());
	// p.setPayQsDate(w.getPayQsDate() == null ? "-" : w.getPayQsDate());
	// p.setPayRemark(w.getPayRemark() == null ? "-" : w.getPayRemark()
	// .trim());
	// p.setPaySendDate((w.getPaySendDate() + "").substring(0, 19));
	// p.setPayTerCode(w.getPayTerCode());
	// String d = w.getId().getPayDate();
	// String tt = w.getPayTime();
	// p.setPayTime(d.substring(0, 4) + "-" + d.substring(4, 6) + "-"
	// + d.substring(6, 8) + " " + tt.substring(0, 2) + ":"
	// + tt.substring(2, 4) + ":" + tt.substring(4, 6));
	// p.setPayTrace(w.getId().getPayTrace());
	// String date = "";
	// if (w.getPayZfDate() == null)
	// p.setPayZfDate("-");
	// else {
	// date = w.getPayZfDate();
	// p
	// .setPayZfDate(date.substring(0, 4) + "-"
	// + date.substring(4, 6) + "-"
	// + date.substring(6, 8) + " "
	// + date.substring(8, 10) + ":"
	// + date.substring(10, 12) + ":"
	// + date.substring(12, 14));
	// }
	// p.setPayZfId(w.getPayZfId());
	// infolist.add(p);
	// }
	// return SUCCESS;
	// }

	public String getBankinfo() {
		LOG.info("读取银行数据...");
		// System.out.println("key1:"+rcvName);
		if (rcvName == null || rcvName.equals("")) {
			return SUCCESS;
		}
		System.out.println("key:" + rcvName);
		rcvName = rcvName.replace("工行", "工商银行");
		rcvName = rcvName.replace("农行", "农业银行");
		rcvName = rcvName.replace("中行", "中国银行");
		rcvName = rcvName.replace("建行", "建设银行");
		rcvName = rcvName.replace("交行", "交通银行");
		rcvName = rcvName.replace("招行", "招商银行");
		rcvName = rcvName.replace("浦发", "浦东发展");
		rcvName = rcvName.replace("深发", "深圳发展");
		String msg = "";
		String tmp[] = rcvName.split(" ");
		String Sql = " where ";
		for (int i = 0; i < tmp.length; i++) {
			if (!tmp[i].equals("")) {
				Sql += " ZFXT_CYZQC like '%" + tmp[i] + "%' and";
			}
		}
		if (Sql.endsWith("and")) {
			Sql = Sql.substring(0, Sql.lastIndexOf("and"));
		}
		banklist = new ArrayList<WtZfxtInfoId>();
		Sql += " order by zfxt_hh ";
		List list = service.query(" from WtZfxtInfoGd" + Sql);
		for (int i = 0; i < list.size(); i++) {
			WtZfxtInfoGd w = (WtZfxtInfoGd) list.get(i);
			banklist.add(w);
		}
		if (banklist.size() > 0) {
			rcvName = "";
		}
		return SUCCESS;
	}

	public String addtcard() {

		LOG.info("绑定T+0卡信息....");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		TcardAccountInfo m = new TcardAccountInfo();
		if (payBankType != null && payBankType.equals("no")) {
			rcvBankname = payInBankName2;
		}
		if (rcvBankname == null || rcvBankname.equals("")) {
			rcvBankname = bankname;
			m.setTInbankno("99999999");
		} else {
			System.out.println(rcvBankname + " " + rcvCdno + " " + rcvName
					+ " " + rcvType + " " + rcvMobile);
			List list = serviceOracle
					.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
							+ rcvBankname + "'");
			if (list.size() != 1) {
				message = "银行检索错误，请重新输入！";
				success = false;
				return SUCCESS;
			}
			WtZfxtInfo w = (WtZfxtInfo) list.get(0);
			m.setTInbankno(w.getId().getZfxtHh());
		}

		if (rcvType.equals("活期储蓄存折"))
			rcvType = "1";
		else if (rcvType.equals("对公帐户"))
			rcvType = "2";
		else if (rcvType.equals("借记卡"))
			rcvType = "3";
		else if (rcvType.equals("信用卡"))
			rcvType = "4";
		else if (rcvType.equals("活期存款账户"))
			rcvType = "5";
		else
			rcvType = "0";

		if (typedk.equals("借记卡"))
			typedk = "0";
		else if (typedk.equals("信用卡"))
			typedk = "2";
		else
			typedk = "1";
		TcardAccountInfoId tid = new TcardAccountInfoId();
		tid.setTCard(tcard.replace(" ", ""));
		tid.setTTermid(termid);
		m.setId(tid);
		m.setTInbank(rcvBankname);
		m.setTIncard(rcvCdno);
		m.setTDate(new Timestamp(new Date().getTime()));
		m.setTPhone(rcvMobile);
		m.setTIntype(rcvType);
		m.setTInname(rcvName);
		m.setTMercode("");
		m.setTTercode("");
		m.setTType(typedk);
		m.setTPercent(new BigDecimal(predk));
		m.setTOrgcode(mpay.getId() + "");
		try {
			serviceOracle.save(m);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "绑定借款卡错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		message = "绑定借款卡信息成功！";
		success = true;
		return SUCCESS;

	}

	public String addred() {
		LOG.info("绑定红卡信息....");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		WtCardAccountInfo ww = new WtCardAccountInfo();
		WtCardAccountInfoId wid = new WtCardAccountInfoId();

		wid.setRcvTerm(rcvTerm.replace(" ", ""));
		wid.setRcvCdno(rcvCdno.replace(" ", ""));

		System.out.println(rcvBankname + " " + rcvCdno + " " + rcvName + " "
				+ rcvType + " " + rcvMobile);
		List list = service
				.query(" from WtZfxtInfoGd where trim(ZFXT_CYZQC) = '"
						+ rcvBankname + "'");
		if (list.size() != 1) {
			message = "银行检索错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		WtZfxtInfoGd w = (WtZfxtInfoGd) list.get(0);
		ww.setRcvBankjx(w.getZfxtCyzjc() != null ? w.getZfxtCyzjc().trim()
				: "-");
		ww.setRcvBankno(w.getZfxtHh());
		ww.setRcvFlag("0");

		if (rcvType.equals("私人"))
			rcvType = "0";
		else
			rcvType = "1";
		ww.setRcvBankname(rcvBankname);
		ww.setRcvDate(new Date());
		ww.setRcvMobile(rcvMobile);
		ww.setRcvType(rcvType);
		ww.setRcvName(rcvName);
		ww.setRcvMerCode("");
		ww.setRcvTermCode("");
		ww.setId(wid);
		try {
			serviceOracle.saveOrUpdate(ww);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "绑定红卡错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		message = "绑定红卡信息成功！";
		success = true;
		return SUCCESS;

	}

	public String addBank() {
		LOG.info("添加汇款人信息....");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayAccount m = new MpayAccount();
		if (payBankType != null && payBankType.equals("no")) {
			rcvBankname = payInBankName2;
		}
		if (rcvBankname == null || rcvBankname.equals("")) {
			rcvBankname = bankname;
			m.setRcvFlag("1");
			m.setRcvBankno("99999999");
			m.setRcvBankjx("-");
		} else {
			System.out.println(rcvBankname + " " + rcvCdno + " " + rcvName
					+ " " + rcvType + " " + rcvMobile);
			List list = serviceOracle
					.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
							+ rcvBankname + "'");
			if (list.size() != 1) {
				message = "银行检索错误，请重新输入！";
				success = false;
				return SUCCESS;
			}
			WtZfxtInfo w = (WtZfxtInfo) list.get(0);
			m.setRcvBankjx(w.getZfxtCyzjc() != null ? w.getZfxtCyzjc().trim()
					: "-");
			m.setRcvBankno(w.getId().getZfxtHh());
			m.setRcvFlag("0");
		}

		if (rcvType.equals("对私"))
			rcvType = "1";
		else if (rcvType.equals("对公"))
			rcvType = "0";
		else
			rcvType = "1";
		m.setRcvBankname(rcvBankname);

		m.setRcvCdno(rcvCdno);
		m.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));

		m.setRcvMobile(rcvMobile);
		m.setRcvType(rcvType);
		m.setRcvName(rcvName);
		m.setRcvMerCode("");
		m.setRcvTermCode("");
		m.setRcvBank(bankname);
		m.setRcvCity(city);
		m.setRcvProvince(province);
		m.setRcvTerm(mpay.getId() + "");
		try {
			service.saveOrUpdate(m);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "添加汇款人错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		message = "添加汇款人信息成功！";
		success = true;
		return SUCCESS;
	}

	public String addcard() {
		LOG.info("绑定红卡转账信息....");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayAccount m = new MpayAccount();
		if (payBankType != null && payBankType.equals("no")) {
			rcvBankname = payInBankName2;
		}
		if (rcvBankname == null || rcvBankname.equals("")) {
			rcvBankname = bankname;
			m.setRcvFlag("1");
			m.setRcvBankno("99999999");
			m.setRcvBankjx("-");
		} else {
			System.out.println(rcvBankname + " " + rcvCdno + " " + rcvName
					+ " " + rcvType + " " + rcvMobile);
			List list = serviceOracle
					.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
							+ rcvBankname + "'");
			if (list.size() != 1) {
				message = "银行检索错误，请重新输入！";
				success = false;
				return SUCCESS;
			}
			WtZfxtInfo w = (WtZfxtInfo) list.get(0);
			m.setRcvBankjx(w.getZfxtCyzjc() != null ? w.getZfxtCyzjc().trim()
					: "-");
			m.setRcvBankno(w.getId().getZfxtHh());
			m.setRcvFlag("0");
		}

		if (rcvType.equals("活期储蓄存折"))
			rcvType = "1";
		else if (rcvType.equals("对公帐户"))
			rcvType = "2";
		else if (rcvType.equals("借记卡"))
			rcvType = "3";
		else if (rcvType.equals("信用卡"))
			rcvType = "4";
		else if (rcvType.equals("活期存款账户"))
			rcvType = "5";
		else
			rcvType = "0";

		m.setRcvBankname(rcvBankname);

		m.setRcvCdno(rcvCdno);
		m.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));

		m.setRcvMobile(rcvMobile);
		m.setRcvType(rcvType);
		m.setRcvName(rcvName);
		m.setRcvMerCode("");
		m.setRcvTermCode("");
		m.setRcvBank(bankname);
		m.setRcvCity(city);
		m.setRcvProvince(province);
		m.setRcvTerm(mpay.getId() + "");
		try {
			service.saveOrUpdate(m);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "添加汇款人错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		message = "添加汇款人信息成功！";
		success = true;
		return SUCCESS;
	}

	public String deletered() {
		LOG.info("删除红卡");
		try {
			WtCardAccountInfo t = (WtCardAccountInfo) serviceOracle
					.loadObject(" from WtCardAccountInfo where concat(RCV_CDNO,RCV_TERM) = '"
							+ id + "' ");
			serviceOracle.delete(t);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "删除红卡错误！";
			success = false;
			return SUCCESS;
		}
		message = "删除红卡成功！";
		success = true;
		return SUCCESS;
	}

	public String deletefee() {
		LOG.info("删除手续费");
		try {
			service.delById(MpayFee.class, Integer.valueOf(userid));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			return SUCCESS;
		}
		message = "删除该用户手续费成功！";
		success = true;
		return SUCCESS;
	}

	public String deletetradefee() {
		LOG.info("删除交易手续费");
		try {
			service.delById(MpayTradeFee.class, Integer.valueOf(userid));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			return SUCCESS;
		}
		message = "删除交易手续费成功！";
		success = true;
		return SUCCESS;
	}

	public String getUserlist() {
		LOG.info("读取用户信息_汇款....");
		ulist = service
				.query(" from MpayUser where id not in (select userid from MpayFee)");
		return SUCCESS;
	}

	public String deletetcard() {
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		LOG.info("删除借款卡信息...");
		try {
			TcardAccountInfo t = (TcardAccountInfo) serviceOracle
					.loadObject(" from TcardAccountInfo where T_CARD = '" + id
							+ "' and T_ORGCODE = '" + mpay.getId() + "' ");
			serviceOracle.delete(t);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "删除借款卡错误！";
			success = false;
			return SUCCESS;
		}
		message = "删除借款卡成功！";
		success = true;
		return SUCCESS;

	}

	public String deletebank() {
		LOG.info("删除汇款人信息...");
		try {
			service.delById(MpayAccount.class, Integer.valueOf(id));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "删除汇款人错误！";
			success = false;
			return SUCCESS;
		}
		message = "删除汇款人成功！";
		success = true;
		return SUCCESS;
	}

	public String addnetremit() {
		LOG.info("代扣支付汇款。。。");
		System.out.println(payId + " " + id + " " + payOutAccount);
		String out = alldk;
		String mm = "";
		if (id.equals("")) {
			message = "提取数据错误";
			success = false;
			return SUCCESS;
		}
		// 代扣
		LOG.info("发送代扣报文");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		Random random = new Random();
		int key = random.nextInt(99999999);
		String traceid = "";
		// 判定代扣渠道
		String str = checkBin(payOutAccount, "1");
		char isDk = str.charAt(0);
		char qdao = str.charAt(1);
		String bank = str.substring(2);
		if (isDk == '1') {// 支持代扣
			if (qdao == '0') {// 互联网渠道
				String MPIURL = Util.ROOTPATH + "/netPay/MPI.properties";
				System.out.println(MPIURL);
				try {
					System.setProperty("javax.net.ssl.trustStore",
							Util.ROOTPATH + "/netPay/jssecacerts");
					TopPayLink.setMPIpropertiesFilePath(MPIURL);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				OrderData tstOrderData = new OrderData();
				// 以下字段是无密代扣交易必输字段
				tstOrderData.setTranCode("1040");
				// 商户ＩＤ（每个商户对应唯一的ID）
				tstOrderData.setMerchantID(NetPayAction.shopno);
				// 订单号（生成规则：从商户ID第四位开始的四位[4401]+取商户ID倒数四位[0027]+8位随机序列号）
				tstOrderData.setMerOrderNum("4038" + "1597"
						+ Util.addZero("" + key, 8));
				traceid = "4038" + "1597" + Util.addZero("" + key, 8);
				// 交易时间(注意位数:14位，交易时间和系统当前时间相差不超过2个小时)：20101125112433
				tstOrderData.setTranDateTime(Util
						.getCurrentDate("yyyyMMddHHmmss"));
				tstOrderData.setPan(payOutAccount);
				// 币种（人民币：156）
				tstOrderData.setCurType("156");
				// 交易金额(单位：分)
				tstOrderData.setTranAmt(Util.moveRightTwo(alldk));
				tstOrderData.setChInfo("", "", "", "", "", "");
				// 以下字段是无密代扣交易可输字段
				tstOrderData.setCustName(payId.substring(0, payId
						.indexOf("/")));
				// tstOrderData.setMsgExt(payRemark);
				NetPayJnls net = new NetPayJnls();
				net.setCustname(tstOrderData.getCustName());
				net.setTrancode("1040");
				net.setMerchantid(tstOrderData.getMerchantID());
				net.setMsgext(id.substring(0, id.length() - 1));
				net.setOrgcode(m.getId() + "");
				net.setPan(tstOrderData.getPan());
				net.setRespcode("SS");
				net.setRespdesc("发送超时");
				if (m.getShopName().indexOf("_") != -1) {
					net.setProdinfo(m.getShopName().substring(0,
							m.getShopName().indexOf("_")).toUpperCase());
					net.setRemark(m.getShopName().substring(5) + "["
							+ m.getMpayUserid() + "]");
				} else {
					net.setRemark(m.getShopName() + "[" + m.getMpayUserid()
							+ "]");
				}
				net.setProdinfo("WEBPAY");
				net.setTranamt(tstOrderData.getTranAmt());
				net.setTrandatetime(new Timestamp(new Date().getTime()));

				NetPayJnlsId nid = new NetPayJnlsId();
				nid.setPepdate(tstOrderData.getTranDateTime().substring(0, 8));
				nid.setMerordernum(tstOrderData.getMerOrderNum());
				net.setId(nid);
				this.serviceOracle.save(net);
				try {
					// 调用交易接口发送到中国银联互联网收单服务平台并同步接收返回结果
					// 商户可根据返回结果进行相关后续处理
					tstOrderData = TopPayLink.CollPayTrans(tstOrderData);

					if (tstOrderData == null) {
						System.out.println("TopPayLink.CollPayTrans error");
					} else {
						// 打印返回交易结果码,返回6个0(000000)表示交易成功
						// 其他的交易码可参考MPI商户插件文档（附录一）.
						System.out.println("Txn RespCode is : "
								+ tstOrderData.getRespCode());
					}
				} catch (PayException ex) {
					System.out
							.println("TopPayLink.CollPayTrans error: RespCode =["
									+ ex.getErrCd() + "]");
					tstOrderData.setRespCode(ex.getErrCd());
					ex.printStackTrace();
					message = "扣款失败，请稍候在试！";
					success = false;
					return SUCCESS;
				} catch (Exception ex) {
					ex.printStackTrace();
					System.out.println("TopPayLink.CollPayTrans error 2");
					message = "扣款失败，请稍候在试！";
					success = false;
					return SUCCESS;
				}
				if (tstOrderData.getRespCode().equals("000000")) {
					mm = "交易成功";
				}
				Connection c = serviceOracle.getConnection();
				try {
					PreparedStatement ps = c
							.prepareStatement("update net_pay_jnls set RESPCODE = '"
									+ tstOrderData.getRespCode()
									+ "',CUPSSYSTIME  = '"
									+ tstOrderData.getCupsSysTime()
									+ "',CUPSTRACENUM = '"
									+ tstOrderData.getCupsTraceNum()
									+ "',SETTLEDATE = '"
									+ tstOrderData.getSettleDate()
									+ "',RESPDESC = '"
									+ tstOrderData.getRespDesc()
									+ "' where MERORDERNUM = '"
									+ tstOrderData.getMerOrderNum()
									+ "' and PEPDATE = '"
									+ Util.getCurrentDate("yyyyMMdd") + "'");
					ps.executeUpdate();
					c.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {// chinapay渠道
				HttpClient httpClient = new HttpClient();
				httpClient.getParams().setParameter(
						HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK");
				String url = "http://apps.chinapay.com/witsingletran/WitSinTranServlet";
				PostMethod postMethod = new PostMethod(url);
				String merId = "808080450004842";
				String transDate = Util.getCurrentDate("yyyyMMdd");
				String orderNo = "50004842" + Util.addZero("" + key, 8);
				traceid = orderNo;
				String transType = "0003";
				String openBankId = Util.checkBank(bank.trim());
				String cardType = "0";
				String cardNo = payOutAccount;
				String usrName1 = payId.substring(0, payId.indexOf("/"));
				String tianUn = NetPayAction.toUnicode(usrName1);
				String tmpUsrName = tianUn;
				String certType = "01";
				String certId = "310000000000000000";
				String curyId = "156";
				String transAmt = Util.left_(Util.moveRightTwo(out), "0", 12);
				String purpose = "";
				String priv1 = "00";
				String tmpPriv1 = NetPayAction.toUnicode(priv1);
				String version = "20100831";
				String gateId = "7008";

				StringBuffer retStr = new StringBuffer();
				retStr.append(merId).append(transDate).append(orderNo).append(
						transType).append(openBankId).append(cardType).append(
						cardNo).append(tmpUsrName).append(certType).append(
						certId).append(curyId).append(transAmt)
						.append(tmpPriv1).append(version).append(gateId);

				SignData signData = new SignData();
				if (Util.ROOTPATH.equals("")) {
					message = "登录超时，请重新登录！";
					success = false;
					return SUCCESS;
				}
				signData.setPath(Util.ROOTPATH + "/chinapay/");
				String data0 = new String(Base64.encode(retStr.toString()
						.getBytes()));
				String chkValue = signData.signForCP(merId, data0);
				NameValuePair[] data = { new NameValuePair("merId", merId),
						new NameValuePair("transDate", transDate),
						new NameValuePair("orderNo", orderNo),
						new NameValuePair("transType", transType),
						new NameValuePair("openBankId", openBankId),
						new NameValuePair("cardType", cardType),
						new NameValuePair("cardNo", cardNo),
						new NameValuePair("usrName", tmpUsrName),
						new NameValuePair("certType", certType),
						new NameValuePair("certId", certId),
						new NameValuePair("curyId", curyId),
						new NameValuePair("transAmt", transAmt),
						new NameValuePair("purpose", purpose),
						new NameValuePair("priv1", tmpPriv1),
						new NameValuePair("version", version),
						new NameValuePair("gateId", gateId),
						new NameValuePair("chkValue", chkValue) };

				postMethod.setRequestBody(data);
				NetPayJnls net = new NetPayJnls();
				net.setCustname(usrName1);
				net.setTrancode("0003");
				net.setMerchantid(merId);
				net.setMsgext(id.substring(0, id.length() - 1));
				net.setOrgcode(m.getId() + "");
				net.setPan(payOutAccount);
				net.setRespcode("SS");
				net.setRespdesc("发送超时");
				if (m.getShopName().indexOf("_") != -1) {
					net.setProdinfo(m.getShopName().substring(0,
							m.getShopName().indexOf("_")).toUpperCase());
					net.setRemark(m.getShopName().substring(5) + "["
							+ m.getMpayUserid() + "]");
				} else {
					net.setRemark(m.getShopName() + "[" + m.getMpayUserid()
							+ "]");
				}
				net.setProdinfo("WEBPAY");
				net.setTranamt(Util.left_(Util.moveRightTwo(out), "0", 12));
				net.setTrandatetime(new Timestamp(new Date().getTime()));

				NetPayJnlsId nid = new NetPayJnlsId();
				nid.setPepdate(transDate);
				nid.setMerordernum(orderNo);
				net.setId(nid);
				this.serviceOracle.save(net);
				int statusCode = 0;
				try {
					statusCode = httpClient.executeMethod(postMethod);
				} catch (HttpException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				if (statusCode != HttpStatus.SC_OK) {
					System.out.println("Method failed:"
							+ postMethod.getStatusLine());
				}
				String tian = "";
				String responseCode = "";
				try {
					tian = postMethod.getResponseBodyAsString();
					System.out.println("html:" + tian);
					responseCode = tian.substring(13, 15);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				String msg = "";

				if (!responseCode.equals("")) {
					if (!responseCode.equals("45")) {
						msg = (String) Util.CHINALIST.get(responseCode);
					} else {
						String tiakong = tian;
						int dex = tian.lastIndexOf("=");

						String tmp = "";
						String tmp2 = "";
						if (tiakong.indexOf("message") != -1) {
							msg = tiakong
									.substring(tiakong.indexOf("message") + 8);
							tmp = tiakong.substring(0, tiakong
									.indexOf("message") + 8);
							tmp2 = msg.substring(msg.indexOf("&", 1));
							msg = msg.substring(0, msg.indexOf("&", 1));
						}
						msg = NetPayAction.tozhCN(msg);
					}
					if (responseCode.equals("00")) {
						mm = "交易成功";
					}
					Connection c = serviceOracle.getConnection();
					try {
						PreparedStatement ps = c
								.prepareStatement("update net_pay_jnls set RESPCODE = '"
										+ responseCode
										+ "',RESPDESC = '"
										+ msg
										+ "' where MERORDERNUM = '"
										+ orderNo
										+ "' and PEPDATE = '"
										+ Util.getCurrentDate("yyyyMMdd") + "'");
						ps.executeUpdate();
						c.close();
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		} else {
			message = "该银行卡不支持代扣！";
			success = false;
			return SUCCESS;
		}
		// 转账
		if (mm.equals("交易成功")) {
			String mp[] = id.split(",");
			for (int i = 0; i < mp.length; i++) {
				MpayPayinfo mpay = (MpayPayinfo) service.loadById(
						MpayPayinfo.class, Integer.valueOf(mp[i]));
				WtPepPayinfo payinfo = new WtPepPayinfo();
				payinfo.setPayAmt(mpay.getPayAmt());
				payinfo.setPayCode("DP1");
				payinfo.setPayFee(mpay.getPayFee());
				payinfo.setPayInBank(mpay.getPayInBankName());
				payinfo.setPayInBankno(mpay.getPayInBankCode());
				payinfo.setPayInName(mpay.getPayInName());
				payinfo.setPayInType(mpay.getPayInType());
				payinfo.setPayOutBankCode("9999");
				payinfo.setPayOutBankCodeInfo("待审核");
				payinfo.setPayPhone(mpay.getPayPhone());
				payinfo.setPayRemark(mpay.getPayRemark());
				payinfo.setPayZfType("9");
				payinfo.setPayZfTrace(traceid);
				payinfo.setPayOutDate(new Date());
				payinfo.setPayZfTermid(m.getMpayUserid());
				payinfo.setPayZfCard(payOutAccount);
				payinfo.setPayOutState("FFFF");
				payinfo.setPayOutStateInfo("待汇出");
				payinfo.setPayZfDate(Util.getCurrentDate("yyyyMMdd"));
				WtPepPayinfoId pid = new WtPepPayinfoId();
				pid.setPayDate(Util.getCurrentDate("yyyyMMddHHmmss"));
				pid.setPayInAccount(mpay.getPayInAccount());
				pid.setPayInTrace(traceid.substring(8) + "#" + i);
				payinfo.setId(pid);
				serviceOracle.save(payinfo);
				serviceOracle.update(" update WtPepPayinfo set pay_date = '"+pid.getPayDate()+"' where pay_in_trace = '"+pid.getPayInTrace()+"' and pay_zf_date = '"+payinfo.getPayZfDate()+"' ");
				service.delete(mpay);
				MpayAccount ca = new MpayAccount();
				ca.setRcvBankjx("");
				ca.setRcvBankname(mpay.getPayInBankName());
				ca.setRcvBankno(mpay.getPayInBankCode());
				ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
				ca.setRcvFlag("0");
				ca.setRcvName(mpay.getPayInName());
				ca.setRcvMobile(mpay.getPayPhone());
				ca.setRcvType(mpay.getPayInType());
				ca.setRcvCdno(mpay.getPayInAccount());
				ca.setRcvMerCode("");
				ca.setRcvTermCode("");
				ca.setRcvTerm(m.getId() + "");
				ca.setRcvBank(mpay.getPayBank());
				ca.setRcvCity(mpay.getPayCity());
				ca.setRcvProvince(mpay.getPayProvince());
				int q = service.query(
						"from MpayAccount where rcv_term = '" + mpay.getId()
								+ "' and rcv_cdno = '" + payOutAccount.trim()
								+ "'").size();
				if (q == 0) {
					try {
						LOG.info("保存新汇款人");
						service.save(ca);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
		message = "提交成功！";
		success = true;
		return SUCCESS;
	}

	public String addremit() {
		LOG.info("添加汇款清单...");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		System.out.println("[" + payInBankName + "]");
		if (payBankType != null && payBankType.equals("no")) {
			payInBankName = payInBankName2;
		}
		List list = serviceOracle
				.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
						+ payInBankName + "'");
		if (list.size() != 1) {
			message = "银行检索错误，请重新输入！";
			success = false;
			return SUCCESS;
		}
		WtZfxtInfo w = (WtZfxtInfo) list.get(0);
		MpayPayinfo m = new MpayPayinfo();
		m.setPayAmt(Util.getAMT(Util.moveRightTwo(payAmt)));
		m.setPayFee(Util.getFEE(Util.moveRightTwo(payFee)));
		m.setPayId(mpay.getId() + "");
		m.setPayInAccount(payInAccount);
		m.setPayInBankCode(w.getId().getZfxtHh());
		m.setPayInBankName(payInBankName);
		if (payInType.equals("对公"))
			payInType = "0";
		else if (payInType.equals("对私"))
			payInType = "1";
		m.setPayInType(payInType);
		m.setPayInName(payInName);
		m.setPayPhone(payPhone);
		m.setPayRemark(payRemark.equals("") ? "汇款" : payRemark);
		m.setPayMerCode("");
		m.setPayTerCode("");
		m.setPayCity(city);
		m.setPayBank(bankname);
		m.setPayProvince(province);
		try {
			service.save(m);
		} catch (Exception e) {
			// TODO: handle exception
			message = "汇款信息生成错误！";
			success = false;
			return SUCCESS;
		}
		message = "汇款信息生成成功！";
		success = true;
		return SUCCESS;
	}

	// public String netremit2() {
	// LOG.info("发送汇款...daikou");
	// UserView mpay = (UserView) getRequest().getSession().getAttribute(
	// "mpay_user");
	// if (payBankType != null && payBankType.equals("no")) {
	// payInBankName = payInBankName2;
	// }
	// List list = serviceOracle
	// .query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
	// + payInBankName + "'");
	// if (list.size() != 1) {
	// message = "银行检索错误，请重新输入！";
	// success = false;
	// return SUCCESS;
	// }
	// WtZfxtInfo winfo = (WtZfxtInfo) list.get(0);
	// MpayAccount ca = new MpayAccount();
	// WtPepPayinfo w = new WtPepPayinfo();
	// WtPepPayinfoId wid = new WtPepPayinfoId();
	// w.setPayAmt(Util.getAMT(Util.moveRightTwo(payAmt)));
	// w.setPayAprespn("FF");
	// w.setPayId(mpay.getId() + "");
	// w.setPayInAccount(payInAccount);
	// w.setPayInBankCode(winfo.getId().getZfxtHh());
	//
	// w.setPayInBankName(payInBankName);
	// w.setPayInName(payInName);
	// if (payInType.equals("活期储蓄存折"))
	// payInType = "1";
	// else if (payInType.equals("对公帐户"))
	// payInType = "2";
	// else if (payInType.equals("借记卡"))
	// payInType = "3";
	// else if (payInType.equals("信用卡"))
	// payInType = "4";
	// else if (payInType.equals("活期存款账户"))
	// payInType = "5";
	// else
	// payInType = "0";
	// w.setPayInType(payInType);
	// w.setPayMerCode("");
	// w.setPayOutAccount("10133061612731345000820002");
	// w.setPayOutBankName("杭州建行宝石支行");
	// w.setPayOutXy("3310110501X2");
	// w.setPayPhone(payPhone);
	// w.setPayZfFee(Util.getFEE(Util.moveRightTwo(payFee)));
	// w.setPayQs("P");
	// w.setPayRemark(payRemark == null || payRemark.equals("") ? "汇款"
	// : payRemark);
	// w.setPayTerCode("");
	// w.setPaySendDate(new Timestamp(new Date().getTime()));
	// w.setPayTime(Util.getCurrentDate("HHmmss"));
	// wid.setPayTrace(Util.addZero(getTrace() + "", 6));
	// wid.setPayDate(Util.getCurrentDate("yyyyMMdd"));
	// payid = Util.getCurrentDate("MMdd")
	// + Util.addZero(getPayTrace() + "", 6);
	// w.setPayZfId(payid);
	// w.setId(wid);
	// try {
	// LOG.info("立刻发生汇款单_" + wid.getPayTrace());
	// serviceOracle.saveOrUpdate(w);
	// String institutionID = "000071";
	// String orderNo = payid;
	// String paymentNo = new Date().getTime() + "";
	// long amount = Long.valueOf(Util.moveRightTwo(payAllAmt));
	// // 2.创建交易请求对象
	// Tx1312Request tx1312Request = new Tx1312Request();
	// tx1312Request.setInstitutionID(institutionID);
	// tx1312Request.setOrderNo(orderNo);
	// tx1312Request.setPaymentNo(paymentNo);
	// tx1312Request.setAmount(amount);
	// tx1312Request.setNotificationURL("");
	// // 3.执行报文处理
	// tx1312Request.process();
	// msg = tx1312Request.getRequestMessage();
	// signature = tx1312Request.getRequestSignature();
	// // System.out.println(msg+"\r\n"+signature);
	// action = PaymentEnvironment.paymentURL;
	// // this.getRequest().setAttribute("message", msg);
	// // this.getRequest().setAttribute("signature", signature);
	// // this.getRequest().setAttribute("action", action);
	// NetPayJnls net = new NetPayJnls();
	// NetPayJnlsId nid = new NetPayJnlsId();
	// net.setMerchantid(institutionID);
	// nid.setMerordernum(payid);
	// nid.setPepdate(Util.getCurrentDate("yyyyMMdd"));
	// net.setId(nid);
	// net.setRespcode("FF");
	// net.setRespdesc("待支付");
	// net.setTrancode("1312");
	// net.setTranamt(amount + "");
	// net.setCupstracenum(paymentNo + "");
	// net.setTrandatetime(new Timestamp(new Date().getTime()));
	// net.setOrgcode(mpay.getId() + "");
	// this.serviceOracle.save(net);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// message = "发生汇款单错误!";
	// success = false;
	// return SUCCESS;
	// }
	// ca.setRcvBankjx("");
	// ca.setRcvBankname(payInBankName);
	// ca.setRcvBankno(winfo.getZfxtSshh());
	// ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
	// ca.setRcvFlag("0");
	// ca.setRcvName(payInName);
	// ca.setRcvMobile(payPhone);
	// ca.setRcvType(payInType);
	// ca.setRcvCdno(payInAccount);
	// ca.setRcvMerCode("");
	// ca.setRcvTermCode("");
	// ca.setRcvTerm(mpay.getId() + "");
	// ca.setRcvBank(bankname);
	// ca.setRcvCity(city);
	// ca.setRcvProvince(province);
	// int q = service.query(
	// "from MpayAccount where rcv_term = '" + mpay.getId()
	// + "' and rcv_cdno = '" + payInAccount.trim() + "'")
	// .size();
	// if (q == 0) {
	// try {
	// LOG.info("保存新汇款人");
	// service.save(ca);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	// try {
	// // Util.sendSMS("汇款单号:" + payid + ",收款人:" + payInName + ",汇款金额:"
	// // + payAmt + "元,手续费" + payFee + "元,请通过网银支付。", mpay
	// // .getMpayTermid());
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// message = "已生产汇款单，请按确认支付！";
	// success = true;
	// return SUCCESS;
	// }

	// public String netremit() {
	// LOG.info("发送汇款...net");
	// UserView mpay = (UserView) getRequest().getSession().getAttribute(
	// "mpay_user");
	// if (payBankType != null && payBankType.equals("no")) {
	// payInBankName = payInBankName2;
	// }
	// List list = serviceOracle
	// .query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
	// + payInBankName + "'");
	// if (list.size() != 1) {
	// message = "银行检索错误，请重新输入！";
	// success = false;
	// return SUCCESS;
	// }
	// WtZfxtInfo winfo = (WtZfxtInfo) list.get(0);
	// MpayAccount ca = new MpayAccount();
	// WtPepPayinfo w = new WtPepPayinfo();
	// WtPepPayinfoId wid = new WtPepPayinfoId();
	// w.setPayAmt(Util.getAMT(Util.moveRightTwo(payAmt)));
	// w.setPayAprespn("FF");
	// w.setPayId(mpay.getId() + "");
	// w.setPayInAccount(payInAccount);
	// w.setPayInBankCode(winfo.getId().getZfxtHh());
	//
	// w.setPayInBankName(payInBankName);
	// w.setPayInName(payInName);
	// if (payInType.equals("活期储蓄存折"))
	// payInType = "1";
	// else if (payInType.equals("对公帐户"))
	// payInType = "2";
	// else if (payInType.equals("借记卡"))
	// payInType = "3";
	// else if (payInType.equals("信用卡"))
	// payInType = "4";
	// else if (payInType.equals("活期存款账户"))
	// payInType = "5";
	// else
	// payInType = "0";
	// w.setPayInType(payInType);
	// w.setPayMerCode("");
	// w.setPayOutAccount("10133061612731345000820002");
	// w.setPayOutBankName("杭州建行宝石支行");
	// w.setPayOutXy("3310110501X2");
	// w.setPayPhone(payPhone);
	// w.setPayZfFee(Util.getFEE(Util.moveRightTwo(payFee)));
	// w.setPayQs("P");
	// w.setPayRemark(payRemark == null || payRemark.equals("") ? "汇款"
	// : payRemark);
	// w.setPayTerCode("");
	// w.setPaySendDate(new Timestamp(new Date().getTime()));
	// w.setPayTime(Util.getCurrentDate("HHmmss"));
	// wid.setPayTrace(Util.addZero(getTrace() + "", 6));
	// wid.setPayDate(Util.getCurrentDate("yyyyMMdd"));
	// payid = Util.getCurrentDate("MMdd")
	// + Util.addZero(getPayTrace() + "", 6);
	// w.setPayZfId(payid);
	// w.setId(wid);
	// try {
	// LOG.info("立刻发生汇款单_" + wid.getPayTrace());
	// serviceOracle.saveOrUpdate(w);
	// String institutionID = "000071";
	// String orderNo = payid;
	// String paymentNo = new Date().getTime() + "";
	// long amount = Long.valueOf(Util.moveRightTwo(payAllAmt));
	// // 2.创建交易请求对象
	// Tx1312Request tx1312Request = new Tx1312Request();
	// tx1312Request.setInstitutionID(institutionID);
	// tx1312Request.setOrderNo(orderNo);
	// tx1312Request.setPaymentNo(paymentNo);
	// tx1312Request.setAmount(amount);
	// tx1312Request.setNotificationURL("");
	// // 3.执行报文处理
	// tx1312Request.process();
	// msg = tx1312Request.getRequestMessage();
	// signature = tx1312Request.getRequestSignature();
	// // System.out.println(msg+"\r\n"+signature);
	// action = PaymentEnvironment.paymentURL;
	// // this.getRequest().setAttribute("message", msg);
	// // this.getRequest().setAttribute("signature", signature);
	// // this.getRequest().setAttribute("action", action);
	// NetPayJnls net = new NetPayJnls();
	// NetPayJnlsId nid = new NetPayJnlsId();
	// net.setMerchantid(institutionID);
	// nid.setMerordernum(payid);
	// nid.setPepdate(Util.getCurrentDate("yyyyMMdd"));
	// net.setId(nid);
	// net.setRespcode("FF");
	// net.setRespdesc("待支付");
	// net.setTrancode("1312");
	// net.setTranamt(amount + "");
	// net.setCupstracenum(paymentNo + "");
	// net.setTrandatetime(new Timestamp(new Date().getTime()));
	// net.setOrgcode(mpay.getId() + "");
	// this.serviceOracle.save(net);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// message = "发生汇款单错误!";
	// success = false;
	// return SUCCESS;
	// }
	// ca.setRcvBankjx("");
	// ca.setRcvBankname(payInBankName);
	// ca.setRcvBankno(winfo.getZfxtSshh());
	// ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
	// ca.setRcvFlag("0");
	// ca.setRcvName(payInName);
	// ca.setRcvMobile(payPhone);
	// ca.setRcvType(payInType);
	// ca.setRcvCdno(payInAccount);
	// ca.setRcvMerCode("");
	// ca.setRcvTermCode("");
	// ca.setRcvTerm(mpay.getId() + "");
	// ca.setRcvBank(bankname);
	// ca.setRcvCity(city);
	// ca.setRcvProvince(province);
	// int q = service.query(
	// "from MpayAccount where rcv_term = '" + mpay.getId()
	// + "' and rcv_cdno = '" + payInAccount.trim() + "'")
	// .size();
	// if (q == 0) {
	// try {
	// LOG.info("保存新汇款人");
	// service.save(ca);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	// try {
	// // Util.sendSMS("汇款单号:" + payid + ",收款人:" + payInName + ",汇款金额:"
	// // + payAmt + "元,手续费" + payFee + "元,请通过网银支付。", mpay
	// // .getMpayTermid());
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// message = "已生产汇款单，请按确认支付！";
	// success = true;
	// return SUCCESS;
	// }

	// public String sendremit() {
	// LOG.info("发送汇款...");
	// UserView mpay = (UserView) getRequest().getSession().getAttribute(
	// "mpay_user");
	// if (payBankType != null && payBankType.equals("no")) {
	// payInBankName = payInBankName2;
	// }
	// List list = serviceOracle
	// .query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
	// + payInBankName + "'");
	// if (list.size() != 1) {
	// message = "银行检索错误，请重新输入！";
	// success = false;
	// return SUCCESS;
	// }
	// WtZfxtInfo winfo = (WtZfxtInfo) list.get(0);
	// MpayAccount ca = new MpayAccount();
	// WtPepPayinfo w = new WtPepPayinfo();
	// WtPepPayinfoId wid = new WtPepPayinfoId();
	// w.setPayAmt(Util.getAMT(Util.moveRightTwo(payAmt)));
	// w.setPayAprespn("FF");
	// w.setPayId(mpay.getId() + "");
	// w.setPayInAccount(payInAccount);
	// w.setPayInBankCode(winfo.getId().getZfxtHh());
	//
	// w.setPayInBankName(payInBankName);
	// w.setPayInName(payInName);
	// if (payInType.equals("活期储蓄存折"))
	// payInType = "1";
	// else if (payInType.equals("对公帐户"))
	// payInType = "2";
	// else if (payInType.equals("借记卡"))
	// payInType = "3";
	// else if (payInType.equals("信用卡"))
	// payInType = "4";
	// else if (payInType.equals("活期存款账户"))
	// payInType = "5";
	// else
	// payInType = "0";
	// w.setPayInType(payInType);
	// w.setPayMerCode("");
	// w.setPayOutAccount("10133061612731345000820002");
	// w.setPayOutBankName("杭州建行宝石支行");
	// w.setPayOutXy("3310110501X2");
	// w.setPayPhone(payPhone);
	// w.setPayZfFee(Util.getFEE(Util.moveRightTwo(payFee)));
	// w.setPayQs("P");
	// w.setPayRemark(payRemark == null || payRemark.equals("") ? "汇款"
	// : payRemark);
	// w.setPayTerCode("");
	// w.setPaySendDate(new Timestamp(new Date().getTime()));
	// w.setPayTime(Util.getCurrentDate("HHmmss"));
	// wid.setPayTrace(Util.addZero(getTrace() + "", 6));
	// wid.setPayDate(Util.getCurrentDate("yyyyMMdd"));
	// payid = Util.getCurrentDate("MMdd")
	// + Util.addZero(getPayTrace() + "", 6);
	// w.setPayZfId(payid);
	// w.setId(wid);
	// try {
	// LOG.info("立刻发生汇款单_" + wid.getPayTrace());
	// serviceOracle.saveOrUpdate(w);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// message = "发生汇款单错误!";
	// success = false;
	// return SUCCESS;
	// }
	// ca.setRcvBankjx("");
	// ca.setRcvBankname(payInBankName);
	// ca.setRcvBankno(winfo.getZfxtSshh());
	// ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
	// ca.setRcvFlag("0");
	// ca.setRcvName(payInName);
	// ca.setRcvMobile(payPhone);
	// ca.setRcvType(payInType);
	// ca.setRcvCdno(payInAccount);
	// ca.setRcvMerCode("");
	// ca.setRcvTermCode("");
	// ca.setRcvTerm(mpay.getId() + "");
	// ca.setRcvBank(bankname);
	// ca.setRcvCity(city);
	// ca.setRcvProvince(province);
	// int q = service.query(
	// "from MpayAccount where rcv_term = '" + mpay.getId()
	// + "' and rcv_cdno = '" + payInAccount.trim() + "'")
	// .size();
	// if (q == 0) {
	// try {
	// LOG.info("保存新汇款人");
	// service.save(ca);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	// try {
	// Util.sendSMS("汇款单号:" + payid + ",收款人:" + payInName + ",汇款金额:"
	// + payAmt + "元,手续费" + payFee + "元,请在终端上支付。", mpay
	// .getMpayTermid());
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// message = "汇款成功";
	// success = true;
	// return SUCCESS;
	// }

	// public String sendremitlist() {
	// LOG.info("发生汇款清单表...");
	// success = true;
	// int k = 0;
	// UserView mp = (UserView) getRequest().getSession().getAttribute(
	// "mpay_user");
	// System.out.println("[" + id + "]");
	// String str[] = id.split(",");
	// float amt = 0;
	// payid = Util.getCurrentDate("MMdd")
	// + Util.addZero(getPayTrace() + "", 6);
	// for (int i = 0; i < str.length; i++) {
	// k++;
	// MpayPayinfo mpay = (MpayPayinfo) service.loadById(
	// MpayPayinfo.class, Integer.valueOf(str[i]));
	// MpayAccount ca = new MpayAccount();
	// WtPepPayinfo w = new WtPepPayinfo();
	// WtPepPayinfoId wid = new WtPepPayinfoId();
	// amt += Integer.valueOf(mpay.getPayAmt());
	// amt += Integer.valueOf(mpay.getPayFee());
	// w.setPayAmt(mpay.getPayAmt());
	// w.setPayAprespn("FF");
	// w.setPayId(mp.getId() + "");
	// w.setPayInAccount(mpay.getPayInAccount());
	// w.setPayInBankCode(mpay.getPayInBankCode());
	// w.setPayInBankName(mpay.getPayInBankName());
	// w.setPayInName(mpay.getPayInName());
	// String paytype = mpay.getPayInType();
	// if (paytype.equals("活期储蓄存折"))
	// paytype = "1";
	// else if (paytype.equals("对公帐户"))
	// paytype = "2";
	// else if (paytype.equals("借记卡"))
	// paytype = "3";
	// else if (paytype.equals("信用卡"))
	// paytype = "4";
	// else if (paytype.equals("活期存款账户"))
	// paytype = "5";
	// else
	// paytype = "0";
	// w.setPayInType(paytype);
	// w.setPayMerCode(mpay.getPayMerCode());
	// w.setPayOutAccount("10133061612731345000820002");
	// w.setPayOutBankName("杭州建行宝石支行");
	// w.setPayOutXy("3310110501X2");
	// w.setPayZfFee(mpay.getPayFee());
	// w.setPayPhone(mpay.getPayPhone());
	// w.setPayQs("P");
	// w.setPayRemark(mpay.getPayRemark());
	// w.setPayTerCode(mpay.getPayTerCode());
	// w.setPaySendDate(new Timestamp(new Date().getTime()));
	// w.setPayTime(Util.getCurrentDate("HHmmss"));
	// wid.setPayTrace(Util.addZero(getTrace() + "", 6));
	// wid.setPayDate(Util.getCurrentDate("yyyyMMdd"));
	// w.setPayZfId(payid);
	// w.setId(wid);
	// try {
	// LOG.info("立刻发生汇款单_" + wid.getPayTrace() + "_" + payid);
	// serviceOracle.saveOrUpdate(w);
	// service.delById(MpayPayinfo.class, Integer.valueOf(str[i]));
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// message = "发生汇款错误!";
	// success = false;
	// continue;
	// }
	// ca.setRcvBankjx("");
	// ca.setRcvBankname(mpay.getPayInBankName());
	// ca.setRcvBankno(mpay.getPayInBankCode());
	// ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
	// ca.setRcvFlag("0");
	// ca.setRcvName(mpay.getPayInName());
	// ca.setRcvMobile(mpay.getPayPhone());
	// ca.setRcvType(mpay.getPayInType());
	// ca.setRcvCdno(mpay.getPayInAccount());
	// ca.setRcvMerCode(mpay.getPayMerCode());
	// ca.setRcvTermCode(mpay.getPayTerCode());
	// ca.setRcvTerm(mp.getId() + "");
	// ca.setRcvBank(mpay.getPayBank());
	// ca.setRcvCity(mpay.getPayCity());
	// ca.setRcvProvince(mpay.getPayProvince());
	// int q = service.query(
	// "from MpayAccount where rcv_term = '" + mp.getId()
	// + "' and rcv_cdno = '"
	// + mpay.getPayInAccount().trim() + "'").size();
	// if (q == 0) {
	// try {
	// LOG.info("保存新汇款人");
	// service.save(ca);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	// }
	// if (!success) {
	// return SUCCESS;
	// }
	// try {
	// Util.sendSMS("汇款单号:" + payid + ",汇款笔数:共" + k + "笔,总金额:" + amt / 100
	// + "元（ 含手续费）,请在终端上支付。", mp.getMpayTermid());
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// message = "发生成功！";
	// success = true;
	// return SUCCESS;
	// }

	public String addfee() {
		MpayFee fee = new MpayFee();
		try {
			MpayUser user = (MpayUser) service.query(
					" from MpayUser where mpay_username = '" + userid + "'")
					.get(0);
			userid = user.getId() + "";
			if (feesType.equals("比例方式")) {
				feesType = "01";
				if (proportion1 != null)
					proportion1 = Float.valueOf(proportion1) / 100 + "";
				if (proportion2 != null)
					proportion2 = Float.valueOf(proportion2) / 100 + "";
				if (proportion3 != null)
					proportion3 = Float.valueOf(proportion3) / 100 + "";
			} else {
				feesType = "02";
			}
			fee.setFactor1(factor1);
			fee.setFactor2(factor2 == null ? "0" : factor2);
			fee.setFactor3(factor3 == null ? "0" : factor3);
			fee.setFeesType(feesType);
			fee.setProportion1(proportion1 == null ? "0" : proportion1);
			fee.setProportion2(proportion2 == null ? "0" : proportion2);
			fee.setProportion3(proportion3 == null ? "0" : proportion3);
			fee.setProportionUp1(proportionUp1 == null ? "0" : proportionUp1);
			fee.setProportionUp2(proportionUp2 == null ? "0" : proportionUp2);
			fee.setProportionUp3(proportionUp3 == null ? "0" : proportionUp3);
			fee.setUserid(Integer.valueOf(userid));
			service.save(fee);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			message = "添加用户汇款手续费失败!";
			return SUCCESS;
		}
		success = true;
		message = "添加用户汇款手续费成功!";
		return SUCCESS;
	}

	public String addtradefee() {
		MpayTradeFee fee = new MpayTradeFee();
		try {
			if (feesType.equals("比例方式")) {
				feesType = "01";
				if (proportion1 != null)
					proportion1 = Util.moveLeftTwo(Float.valueOf(proportion1)
							+ "");
				if (proportion2 != null)
					proportion2 = Util.moveLeftTwo(Float.valueOf(proportion2)
							+ "");
				if (proportion3 != null)
					proportion3 = Util.moveLeftTwo(Float.valueOf(proportion3)
							+ "");
			} else {
				feesType = "02";
			}
			fee.setFactor1(factor1);
			fee.setFactor2(factor2 == null ? "0" : factor2);
			fee.setFactor3(factor3 == null ? "0" : factor3);
			fee.setFeesType(feesType);
			fee.setProportion1(proportion1 == null ? "0" : proportion1);
			fee.setProportion2(proportion2 == null ? "0" : proportion2);
			fee.setProportion3(proportion3 == null ? "0" : proportion3);
			fee.setProportionUp1(proportionUp1 == null ? "0" : proportionUp1);
			fee.setProportionUp2(proportionUp2 == null ? "0" : proportionUp2);
			fee.setProportionUp3(proportionUp3 == null ? "0" : proportionUp3);
			fee.setRemark(remark);
			fee.setMercode(mercode);
			fee.setTercode(tercode);
			fee.setTrancde(trancde);
			service.save(fee);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			message = "添加交易手续费失败!";
			return SUCCESS;
		}
		success = true;
		message = "添加交易手续费成功!";
		return SUCCESS;
	}

	public String deleteremit() {
		LOG.info("删除汇款清单...");
		// System.out.println("[" + id + "]");
		String str[] = id.split(",");
		try {
			for (int i = 0; i < str.length; i++) {
				service.delById(MpayPayinfo.class, Integer.valueOf(str[i]));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message = "删除汇款单错误！";
			success = false;
			return SUCCESS;
		}
		message = "删除汇款单成功！";
		success = true;
		return SUCCESS;
	}

	public String getLinklist() {
		LOG.info("读取常用联系人");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		String sql = " where rcv_term = '" + m.getId() + "' ";
		if (rcvFlag != null && rcvFlag.equals("1")) {
			sql += " and rcv_flag = '1' ";
		} else if (rcvFlag!=null&&rcvFlag.equals("2")){
			sql += " and rcv_flag = '1' and RCV_MOBILE != null ";
		}else {
			sql += " and rcv_flag = '0' ";
		}
		paylist = new ArrayList<MpayAccount>();
		List tmp = service.query("from MpayAccount " + sql);
		for (int i = 0; i < tmp.size(); i++) {
			MpayAccount mpay = (MpayAccount) tmp.get(i);
			if (rcvFlag!=null&&rcvFlag.equals("2")){
				mpay.setRcvBankjx(mpay.getRcvMobile()+"/"+mpay.getRcvName()
						+ "/****"
						+ mpay.getRcvCdno().substring(
								mpay.getRcvCdno().trim().length() - 4) + "/"
						+ mpay.getRcvBankname());
			}else{
			mpay.setRcvBankjx(mpay.getRcvName()
					+ "/****"
					+ mpay.getRcvCdno().substring(
							mpay.getRcvCdno().trim().length() - 4) + "/"
					+ mpay.getRcvBankname());
			}
			paylist.add(mpay);
		}
		return SUCCESS;
	}

	public String getfee() {
		LOG.info("计算汇款手续费...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayFee fee = (MpayFee) service.loadById(MpayFee.class, m.getId());
		if (fee == null) {
			payFee = "0";
			return SUCCESS;
		}
		try {
			float amt = Float.valueOf(payAmt);
			float f1 = Float.valueOf(fee.getFactor1());
			float f2 = Float.valueOf(fee.getFactor2());
			float f3 = Float.valueOf(fee.getFactor3());
			float fees = 0;
			if (fee.getFeesType().equals("01")) {// 比例计算
				if (f1 == 0) {
					// 使用条件1
					fees = amt * Float.valueOf(fee.getProportion1());
					if (!fee.getProportionUp1().equals("0")) {
						if (fees > Float.valueOf(fee.getProportionUp1())) {
							fees = Float.valueOf(fee.getProportionUp1());
						}
					}
				} else if (f2 == 0) {
					if (amt > f1) {
						// 使用条件2
						fees = amt * Float.valueOf(fee.getProportion2());
						if (!fee.getProportionUp2().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp2())) {
								fees = Float.valueOf(fee.getProportionUp2());
							}
						}
					} else {
						// 使用条件1
						fees = amt * Float.valueOf(fee.getProportion1());
						if (!fee.getProportionUp1().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp1())) {
								fees = Float.valueOf(fee.getProportionUp1());
							}
						}
					}
				} else if (f3 == 0) {
					if (amt > f2) {
						// 使用条件3
						fees = amt * Float.valueOf(fee.getProportion3());
						if (!fee.getProportionUp3().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp3())) {
								fees = Float.valueOf(fee.getProportionUp3());
							}
						}
					} else if (amt > f1) {
						// 使用条件2
						fees = amt * Float.valueOf(fee.getProportion2());
						if (!fee.getProportionUp2().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp2())) {
								fees = Float.valueOf(fee.getProportionUp2());
							}
						}
					} else {
						// 使用条件1
						fees = amt * Float.valueOf(fee.getProportion1());
						if (!fee.getProportionUp1().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp1())) {
								fees = Float.valueOf(fee.getProportionUp1());
							}
						}
					}
				} else {
					if (amt > f3) {
						// 不计算
						return SUCCESS;
					} else {
						if (amt > f2) {
							// 使用条件3
							fees = amt * Float.valueOf(fee.getProportion3());
							if (!fee.getProportionUp3().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp3())) {
									fees = Float
											.valueOf(fee.getProportionUp3());
								}
							}
						} else if (amt > f1) {
							// 使用条件2
							fees = amt * Float.valueOf(fee.getProportion2());
							if (!fee.getProportionUp2().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp2())) {
									fees = Float
											.valueOf(fee.getProportionUp2());
								}
							}
						} else {
							// 使用条件1
							fees = amt * Float.valueOf(fee.getProportion1());
							if (!fee.getProportionUp1().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp1())) {
									fees = Float
											.valueOf(fee.getProportionUp1());
								}
							}
						}
					}
				}
				if (fees < 0.01)
					fees = 0;
				payFee = fees + "";

			} else if (fee.getFeesType().equals("02")) {// 固定计算
				if (f1 == 0) {
					// 使用条件1
					fees = Float.valueOf(fee.getProportion1());
				} else if (f2 == 0) {
					if (amt > f1) {
						// 使用条件2
						fees = Float.valueOf(fee.getProportion2());
					} else {
						// 使用条件1
						fees = Float.valueOf(fee.getProportion1());
					}
				} else if (f3 == 0) {
					if (amt > f2) {
						// 使用条件3
						fees = Float.valueOf(fee.getProportion3());
					} else if (amt > f1) {
						// 使用条件2
						fees = Float.valueOf(fee.getProportion2());
					} else {
						// 使用条件1
						fees = Float.valueOf(fee.getProportion1());
					}
				} else {
					if (amt > f3) {
						// 不计算
						return SUCCESS;
					} else {
						if (amt > f2) {
							// 使用条件3
							fees = Float.valueOf(fee.getProportion3());
						} else if (amt > f1) {
							// 使用条件2
							fees = Float.valueOf(fee.getProportion2());
						} else {
							// 使用条件1
							fees = Float.valueOf(fee.getProportion1());
						}
					}
				}
				if (fees < 0.01)
					fees = 0;
				payFee = fees + "";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			payFee = null;
		}
		return SUCCESS;
	}

	public String getfee(String src) {
		LOG.info("计算汇款手续费_后台...");
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayFee fee = (MpayFee) service.loadById(MpayFee.class, m.getId());
		if (fee == null) {
			payFee = "0";
			return "00000000";
		}
		try {
			float amt = Float.valueOf(src);
			float f1 = Float.valueOf(fee.getFactor1());
			float f2 = Float.valueOf(fee.getFactor2());
			float f3 = Float.valueOf(fee.getFactor3());
			float fees = 0;
			if (fee.getFeesType().equals("01")) {// 比例计算
				if (f1 == 0) {
					// 使用条件1
					fees = amt * Float.valueOf(fee.getProportion1());
					if (!fee.getProportionUp1().equals("0")) {
						if (fees > Float.valueOf(fee.getProportionUp1())) {
							fees = Float.valueOf(fee.getProportionUp1());
						}
					}
				} else if (f2 == 0) {
					if (amt > f1) {
						// 使用条件2
						fees = amt * Float.valueOf(fee.getProportion2());
						if (!fee.getProportionUp2().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp2())) {
								fees = Float.valueOf(fee.getProportionUp2());
							}
						}
					} else {
						// 使用条件1
						fees = amt * Float.valueOf(fee.getProportion1());
						if (!fee.getProportionUp1().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp1())) {
								fees = Float.valueOf(fee.getProportionUp1());
							}
						}
					}
				} else if (f3 == 0) {
					if (amt > f2) {
						// 使用条件3
						fees = amt * Float.valueOf(fee.getProportion3());
						if (!fee.getProportionUp3().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp3())) {
								fees = Float.valueOf(fee.getProportionUp3());
							}
						}
					} else if (amt > f1) {
						// 使用条件2
						fees = amt * Float.valueOf(fee.getProportion2());
						if (!fee.getProportionUp2().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp2())) {
								fees = Float.valueOf(fee.getProportionUp2());
							}
						}
					} else {
						// 使用条件1
						fees = amt * Float.valueOf(fee.getProportion1());
						if (!fee.getProportionUp1().equals("0")) {
							if (fees > Float.valueOf(fee.getProportionUp1())) {
								fees = Float.valueOf(fee.getProportionUp1());
							}
						}
					}
				} else {
					if (amt > f3) {
						// 不计算
						return Util.getFEE(Util.moveRightTwo(payFee));
					} else {
						if (amt > f2) {
							// 使用条件3
							fees = amt * Float.valueOf(fee.getProportion3());
							if (!fee.getProportionUp3().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp3())) {
									fees = Float
											.valueOf(fee.getProportionUp3());
								}
							}
						} else if (amt > f1) {
							// 使用条件2
							fees = amt * Float.valueOf(fee.getProportion2());
							if (!fee.getProportionUp2().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp2())) {
									fees = Float
											.valueOf(fee.getProportionUp2());
								}
							}
						} else {
							// 使用条件1
							fees = amt * Float.valueOf(fee.getProportion1());
							if (!fee.getProportionUp1().equals("0")) {
								if (fees > Float
										.valueOf(fee.getProportionUp1())) {
									fees = Float
											.valueOf(fee.getProportionUp1());
								}
							}
						}
					}
				}
				if (fees < 0.01)
					fees = 0;
				payFee = fees + "";

			} else if (fee.getFeesType().equals("02")) {// 固定计算
				if (f1 == 0) {
					// 使用条件1
					fees = Float.valueOf(fee.getProportion1());
				} else if (f2 == 0) {
					if (amt > f1) {
						// 使用条件2
						fees = Float.valueOf(fee.getProportion2());
					} else {
						// 使用条件1
						fees = Float.valueOf(fee.getProportion1());
					}
				} else if (f3 == 0) {
					if (amt > f2) {
						// 使用条件3
						fees = Float.valueOf(fee.getProportion3());
					} else if (amt > f1) {
						// 使用条件2
						fees = Float.valueOf(fee.getProportion2());
					} else {
						// 使用条件1
						fees = Float.valueOf(fee.getProportion1());
					}
				} else {
					if (amt > f3) {
						// 不计算
						return Util.getFEE(Util.moveRightTwo(payFee));
					} else {
						if (amt > f2) {
							// 使用条件3
							fees = Float.valueOf(fee.getProportion3());
						} else if (amt > f1) {
							// 使用条件2
							fees = Float.valueOf(fee.getProportion2());
						} else {
							// 使用条件1
							fees = Float.valueOf(fee.getProportion1());
						}
					}
				}
				if (fees < 0.01)
					fees = 0;
				payFee = fees + "";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			success = false;
			payFee = null;
			return "00000000";
		}
		return Util.getFEE(Util.moveRightTwo(payFee));
	}

	public void upload() {
		System.out.println("导入文件");
		// System.out.println(file.size());
		// System.out.println(fileFileName.size());
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		int s = 0;
		int f = 0;
		File infile = file.get(0);
		String msg = "{success:true,message:'导入成功'}";
		try {
			InputStreamReader read = new InputStreamReader(new FileInputStream(
					infile), "GBK");
			BufferedReader reader = new BufferedReader(read);
			String str = new String();
			int i = 0;

			while ((str = reader.readLine()) != null) {
				if (!str.startsWith("#")) {
					String tmp[] = str.split(",");
					System.out.println("dfdf" + str);
					if (tmp.length == 7) {
						// System.out.println(str);
						List list = serviceOracle
								.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
										+ tmp[5].trim() + "'");
						if (list.size() == 1) {
							WtZfxtInfo w = (WtZfxtInfo) list.get(0);
							MpayPayinfo m = new MpayPayinfo();
							m.setPayAmt(Util.getAMT(Util.moveRightTwo(tmp[2])));
							m.setPayId(mpay.getId() + "");
							m.setPayInAccount(tmp[1]);
							m.setPayInBankCode(w.getId().getZfxtHh());
							m.setPayInBankName(tmp[5]);
							m.setPayInType(tmp[6]);
							m.setPayInName(tmp[0]);
							m.setPayPhone(tmp[4]);

							m.setPayFee(getfee(tmp[2]));
							m.setPayRemark(tmp[3].equals("") ? "汇款" : tmp[3]);
							m.setPayMerCode("");
							m.setPayTerCode("");
							service.save(m);
							s++;
						} else {
							f++;
						}
					} else {
						f++;
					}
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			msg = "{success:false,message:'导入失败请查看文件格式是否正确'}";
		}
		try {
			msg = "{success:true,message:'导入成功<br>成功:" + s + "失败:" + f + "'}";
			HttpServletResponse response = this.getResponse();
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html");
			response.getWriter().write(msg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// public int getTrace() {
	// int i = 0;
	// List tmp = serviceOracle
	// .query(" from WtPepPayinfo order by to_number(pay_trace) desc ");
	// if (tmp.size() > 0) {
	// WtPepPayinfo w = (WtPepPayinfo) tmp.get(0);
	// i = Integer.valueOf(w.getId().getPayTrace().trim());
	// }
	// i += 1;
	// if (i == 999999)
	// i = 1;
	// return i;
	// }

	// public int getPayTrace() {
	// int i = 0;
	// List tmp = serviceOracle
	// .query(" from WtPepPayinfo where pay_zf_id is not null order by substr(pay_zf_id,5) desc ");
	// if (tmp.size() > 0) {
	// WtPepPayinfo w = (WtPepPayinfo) tmp.get(0);
	// // System.out.println(w.getPayZfId()+" "+w.getPayZfId().substring(4));
	// if (w.getPayZfId() != null && !w.getPayZfId().equals("")) {
	// i = Integer.valueOf(w.getPayZfId().substring(4));
	// }
	// }
	// i += 1;
	// if (i == 999999)
	// i = 1;
	// return i;
	// }

	public String checkQS(String value) {
		if (value.equals("0")) {
			return "成功";
		} else if (value.equals("1")) {
			return "失败";
		} else if (value.equals("F")) {
			return "已付款";
		} else if (value.equals("S")) {
			return "已处理";
		} else if (value.equals("P")) {
			return "待付款";
		} else {
			return value;
		}
	}

	public void test() throws Exception {
		PaymentEnvironment
				.initialize("E:\\workspace\\DemoTestWeb\\WebContent\\");
		System.out.println("test");
		String institutionID = "000071";
		String serialNumber = new Date().getTime() + "";
		String orderNo = "0425000173";
		long amount = Long.valueOf("10000");
		String remark = "测试";
		int accountType = 12;
		String paymentAccountName = "";
		String paymentAccountNumber = "";
		String bankID = "305";
		String accountName = "上海华势信息科技有限公司";
		String accountNumber = "462010100100364346";
		String province = "河南";
		String city = "郑州";
		String bank = "兴业银行郑州分行营业部";
		// 2.创建交易请求对象
		Tx1345Request tx1345Request = new Tx1345Request();
		tx1345Request.setInstitutionID(institutionID);
		tx1345Request.setSerialNumber(serialNumber);
		tx1345Request.setOrderNo(orderNo);
		tx1345Request.setAmount(amount);
		tx1345Request.setRemark(remark);
		tx1345Request.setSumRequired("1");
		tx1345Request.setAccountType(accountType);
		tx1345Request.setPaymentAccountName(paymentAccountName);
		tx1345Request.setPaymentAccountNumber(paymentAccountNumber);
		BankAccount bankAccount = new BankAccount();
		bankAccount.setBankID(bankID);
		bankAccount.setAccountName(accountName);
		bankAccount.setAccountNumber(accountNumber);
		bankAccount.setProvince(province);
		bankAccount.setCity(city);
		bankAccount.setBranchName(bank);
		tx1345Request.setBankAccount(bankAccount);
		System.out.println(tx1345Request.toString());
		// 3.执行报文处理
		tx1345Request.process();
		System.out.println(tx1345Request.getRequestMessage());
		System.out.println(tx1345Request.getRequestSignature());
		// 4.与支付平台进行通讯
		TxMessenger txMessenger = new TxMessenger();
		// 0:message; 1:signature
		String[] respMsg = txMessenger.send(tx1345Request.getRequestMessage(),
				tx1345Request.getRequestSignature());
		// 5.交易结果处理 0:message; 1:signature
		Tx134xResponse tx134xResponse = new Tx134xResponse(respMsg[0],
				respMsg[1]);
		// 6. 如果返回正常报文
		if ("2000".equals(tx134xResponse.getCode())) {
			// 商户根据自己的业务要求编写相应的业务处理代码
		}
		System.out.println(tx134xResponse.getResponsePlainText());

	}

	public static void main(String args[]) {
		try {
			new RemitAction().test();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// 校验卡BIN
	public String checkBin(String card, String flag) {
		String sql = "select t.net_iss_flag,t.net_iss_card,p.lc_card,NET_ISS_RZ,NET_ISS_DK,NET_ISS_NAME from net_pay_iss t, pep_card_limit p where t.net_iss_id = trim(p.lc_iss_id) and length(trim('"
				+ card
				+ "')) = p.lc_cdnopos and substr(trim('"
				+ card
				+ "'),0,length(trim(p.lc_head)))= trim(p.lc_head)";
		System.out.println(sql);
		Connection c = serviceOracle.getConnection();
		String tmp = "";
		try {
			PreparedStatement ps = c.prepareStatement(sql);
			ResultSet rset = ps.executeQuery();
			rset.next();
			String net_iss_flag = rset.getString(1);
			String net_iss_card = rset.getString(2);
			String lc_card = rset.getString(3);
			String net_rz = rset.getString(4);
			String net_dk = rset.getString(5);
			String net_name = rset.getString(6);
			if (flag.equals("0")) {// 消费
				if (net_iss_flag.equals("0") || net_iss_flag.equals("2")) {
					if (lc_card.equals("D")) {
						if (net_iss_card.equals("0")
								|| net_iss_card.equals("2")) {
							tmp = 1 + net_dk;
						}
					} else {
						if (net_iss_card.equals("1")
								|| net_iss_card.equals("2")) {
							tmp = 1 + net_dk;
						}
					}
				}
			} else if (flag.equals("1")) {// 代扣
				if (net_iss_flag.equals("1") || net_iss_flag.equals("2")) {
					if (lc_card.equals("D")) {
						if (net_iss_card.equals("0")
								|| net_iss_card.equals("2")) {
							tmp = 1 + net_dk + net_name;
						}
					} else {
						if (net_iss_card.equals("1")
								|| net_iss_card.equals("2")) {
							tmp = 1 + net_dk + net_name;
						}
					}
				}
			} else if (flag.equals("2")) {// 认证
				if (net_rz != null && net_rz.equals("1")) {
					tmp = 1 + net_dk;
				} else {
					tmp = 0 + net_dk;
				}
			}
			c.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			tmp = "00";
		}

		return tmp;
	}

}
